Hi, hungryhobo,
you correct about not looping the sheets in the opened workbook as I misread and wrote code to open several workbooks instead.
Please give this a try:
Sub NewWeek_3()
Dim myWb As Workbook
Dim wb2 As Workbook
Dim rngCell As Range
Dim lngCounter As Long
Dim lngLast As Long
Dim wsAct As Worksheet
Application.ScreenUpdating = False
Set myWb = ActiveWorkbook
Set wsAct = myWb.ActiveSheet
lngLast = wsAct.Cells(Rows.Count, "A").End(xlUp).Row
Set wb2 = Workbooks.Open(Filename:="E:\archive\wb" & wsAct.Range("D2").Value & ".xlsx")
For lngCounter = 2 To lngLast
With wb2.Sheets(wsAct.Cells(lngCounter, "A").Value)
For Each rngCell In .Range("A1:A" & .Range("A" & .Rows.Count).End(xlUp).Row)
If Trim(rngCell.Value) <> vbNullString Then rngCell.Value = Trim(rngCell.Value)
Next rngCell
End With
Next lngCounter
wb2.Close True
Application.Goto wsAct.Cells(1)
Application.ScreenUpdating = True
Set rngCell = Nothing
Set wb2 = Nothing
Set wsAct = Nothing
Set myWb = Nothing
End Sub
Please consider to use this instead of the loop
For lngCounter = 2 To lngLast
With wb2.Sheets(wsAct.Cells(lngCounter, "A").Value)
With .Range("A1:A" & .Range("A" & .Rows.Count).End(xlUp).Row)
.Value = .Value
End With
End With
Next lngCounter
Ciao,
Holger
Bookmarks