PDA

View Full Version : Question about create Macro manage information.



thanhvanchi
12-12-2016, 01:12 AM
Hello everyone!
I was studying the application on excel.
I would be really happy if somebody could help me with the following problem:


I have some excel files. The Team file and the Team members files. I am trying to create a macro in The Team File to do the following:


For every Row in the Team file go to the Team members file find some information and copy them. The Members files are in the same folder and they are named after the people's names. It seams that VBA does not accept the name of the Workbook of every member, since I am trying to add it with cell references of the members names:


for r = 2 To 240
workbook ("Filepath" & Cell(r, 2).Value & "_" & Cell(r,3).Value & ".xls").Activate
etc.
next r


Any Ideas how I could make it work?
I would be grateful for your help.
Thank you very much!

Bob Phillips
12-12-2016, 05:06 AM
Maybe some of those names have characters that are invalid as a workbook filename. Give an example of one that is 'not accepted'.

offthelip
12-12-2016, 05:09 AM
I have spotted various errors in your code, but I haven't test this so there may be more, but giove it a try:

Dim Pathnm As String
Dim filenm As String
Pathnm = ActiveWorkbook.Path
For r = 2 To 240
filenm = "\" & Cells(r, 2).Value & "_" & Cells(r, 3).Value & ".xls"
Workbooks(Pathnm & filenm).Activate
Next r