aharris2693
Programmer
I am relatively new with using VBA for Excel and I am trying to reference two workbooks at the same time. What I want is for the user to make changes to a weekly "move list" that will then update another sheet that is a seating chart at the end of each week. Based on the names in the move list, I want to search the seating chart and then make the appropriate changes. I tried recording a macro that opens the new workbook and makes a simple change just to see the code for using 2 books. This worked and it still worked when I adjusted for my search variables. My question, finally, is why doesn't this same code work when I put it under the click event of a command button. Below is the code, but like I said it works as a macro, so it may not be of any assistance.
Sub updateSheets()
a = 2
Do Until a = 6
strName = Range("Move_List!A" & a)
strOffice = Range("Move_List!F" & a)
MsgBox (strName & ", " & strOffice)
ChDir "F:\DATA\USERS\HarrisAL\Mitch"
Workbooks.Open FileName:= _
"\\WIL-OPS\VOL1\DATA\USERS\HarrisAL\Mitch\Wilmington_Seating_Chart.xls"
x = 2
Do Until x = 1000
If strName <> "" Then
If Range("D" & x) = strName Then
Range("B" & x).Select
ActiveCell.Value = strOffice
End If
End If
x = x + 1
Loop
ActiveWorkbook.Save
ActiveWindow.Close
a = a + 1
Loop
End Sub
Thanks a lot for any help
Sub updateSheets()
a = 2
Do Until a = 6
strName = Range("Move_List!A" & a)
strOffice = Range("Move_List!F" & a)
MsgBox (strName & ", " & strOffice)
ChDir "F:\DATA\USERS\HarrisAL\Mitch"
Workbooks.Open FileName:= _
"\\WIL-OPS\VOL1\DATA\USERS\HarrisAL\Mitch\Wilmington_Seating_Chart.xls"
x = 2
Do Until x = 1000
If strName <> "" Then
If Range("D" & x) = strName Then
Range("B" & x).Select
ActiveCell.Value = strOffice
End If
End If
x = x + 1
Loop
ActiveWorkbook.Save
ActiveWindow.Close
a = a + 1
Loop
End Sub
Thanks a lot for any help