Guys, Not sure if this is enough information but I am trying to get the below code in yellow to loop through each worksheet and the data retrieved (stacked) in columns A:C on the CommercialInvoiceConsolidation worksheet. Is it possible to run a loop through each worksheet?
Rich (BB code):
Dim CS As Worksheet, ws1 As Worksheet, SH As Worksheet, Ws As Worksheet
Dim LR1 As Long, NR As Long, sCol As Long
Dim LR99 As Double
Dim sName As Boolean, SortStr As String
Dim wb As Workbook
Dim DestSh As Worksheet
Dim Ls As Integer, Lw As Integer
Dim LastRow As Long, LastRowA As Long, LastRowB As Long, LastRowC As Long, LastRowD As Long, LastA As Long, LastD As Long, C As Long
Dim i As Integer
Application.ScreenUpdating = False
Set wb = ThisWorkbook
Set DestSh = wb.Sheets("CommercialInvoiceConsolidation")
' Loop through worksheets that start with the name "20"
i = 2
'Setup
Set CS = ActiveWorkbook.Sheets("CommercialInvoiceConsolidation")
NR = 2
'Process each data sheet
For Each ws1 In Worksheets
If ws1.Name <> CS.Name And _
ws1.Name <> "CommercialInvoiceConsolidation" Then
LR1 = ws1.Range("C" & ws1.Rows.Count).End(xlUp).Row
LR99 = LR1 - 29
numPO = Cells(22, 4).Value
numInvoice = Cells(7, 9).Value
DatDate = Cells(8, 9).Value
If NR = 1 Then
End If
X = 2
Do Until X = LR99 + 2
If Cells(X, 1).Value = "" Then
Cells(X, 1).Value = numPO
Cells(X, 2).Value = numInvoice
Cells(X, 3).Value = DatDate
End If
X = X + 1
Loop
End If
Next ws1
End Sub
Last edited by a moderator: