dpaton05
Well-known Member
- Joined
- Aug 14, 2018
- Messages
- 2,375
- Office Version
- 365
- 2016
- Platform
- Windows
I have some code that when I try and run it, I get an error message saying next without for and it has the next highlighted. What am I missing?
Code:
Sub cmdCopyr()
Application.ScreenUpdating = False
'declare variables
Dim TableLastRow As Long
Dim LastRow As Long
Dim TableNumberRows As Long
Dim iCounter As Long 'counter of for..next loop
Dim tblRows As Integer 'number of rows in tblCosting
Dim tblrow As ListRow 'specific row in tblCosting
Dim Combo As String 'Combo worksheet name
Dim Start As Long 'number of first row in tblCosting
'assign values to variables
TableLastRow = Worksheets("home").ListObjects("tblCosting").Rows(Rows.Count).Row 'last row in tblCosting of home sheet
LastRow = Worksheets(Combo).Cells(Rows.Count, "A").End(xlUp).Row + 1 'number of first empty row in column A of Combo
Combo = Worksheets("Home").Range("Y5") 'concaternation of cells to get name of worksheet to put data
TableNumberRows = ListObjects("tblCosting").Range.Rows.Count
Start = "5"
' With tblCosting.Range
' TableLastRow = .Rows(Rows.Count).Row
' End With
For iCounter = Start To TableLastRow Step 1
ListObjects("tblCosting").Range("A" & iCounter & ":" & "J" & iCounter).copy
With Worksheets(Combo).Cells(LastRow, iCounter)
.PasteSpecial Paste:=xlPasteValues
.Columns("A").NumberFormat = "dd/mm/yyyy"
ListObjects("tblCosting").Range("O" & iCounter).copy
Worksheets(Combo).Cells(LastRow, 11).PasteSpecial Paste:=xlPasteValues
ListObjects("tblCosting").Range("AD" & iCounter & ":" & "AF" & iCounter).copy
Worksheets(Combo).Cells(LastRow, 14).PasteSpecial Paste:=xlPasteValues
[COLOR=#ff0000]Next [/COLOR]iCounter
Application.ScreenUpdating = True
End Sub