dpaton05
Well-known Member
- Joined
- Aug 14, 2018
- Messages
- 2,362
- Office Version
- 365
- 2016
- Platform
- Windows
Is there anything wrong with the syntax of my for next loop?
Thanks
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 sht As Worksheet
Dim Start As Long 'number of first row in tblCosting
Dim Costing As String
'assign values to variables
Set sht = Worksheets("home")
With sht
TableLastRow = Split(Sheets("Home").ListObjects("tblCosting").DataBodyRange.Address, "$")(4) 'last row in tblCosting of home sheet
Combo = Worksheets("Home").Range("Y5") 'concaternation of cells to get name of worksheet to put data
LastRow = Worksheets(Combo).Cells(Rows.Count, "A").End(xlUp).Row + 1 'number of first empty row in column A of Combo
Costing = Worksheets("home").ListObjects("tblCosting")
' TableNumberRows = Rows("tblCosting") 'Worksheets("home").ListObjects("tblCosting").Rows.Count
Start = "5"
For iCounter = Start To TableLastRow Step 1
.ListObjects("tblCosting").Range.Cells(iCounter, 1).Resize(, 10).copy
With Worksheets(Combo).Cells(LastRow, iCounter)
.PasteSpecial Paste:=xlPasteValues
.Columns("A").NumberFormat = "dd/mm/yyyy"
End With
.ListObjects("tblCosting").Range.Cells(iCounter, 1).copy
Worksheets(Combo).Cells(LastRow, 11).PasteSpecial Paste:=xlPasteValues
.ListObjects("tblCosting").Range.Cells(iCounter, 30).Resize(, 32).copy
Worksheets(Combo).Cells(LastRow, 14).PasteSpecial Paste:=xlPasteValues
Next iCounter
'Check if activities is selected in column I
If Worksheets("home").Range("I5") = "Activities" Then
Worksheets(Combo).Range("K" & LastRow).Value = Worksheets("home").Range("AC" & LastRow) 'copy formula to total column if activities are selected
'Worksheets(Combo).Range("I" & Lastrow).ClearContents 'clear gst component if activities are selected
Else
Worksheets(Combo).Range("L" & LastRow).Formula = "=K" & LastRow & "*.1" 'if activities are not selected, GST formula will be added in to column H
Worksheets(Combo).Range("M" & LastRow).Formula = "=L" & LastRow & "+K" & LastRow 'if activities are not selected, add formula in to column I that will sum columns G + H
End If
Worksheets(Combo).Columns("H:J").NumberFormat = "$#,##0.00" 'format values in columns G to I of Combo
Call SortDates 'format cells to be in ascending date order
End With
Application.CutCopyMode = False 'cancel Cut or Copy mode
Application.ScreenUpdating = True
End Sub
Thanks
Last edited: