New to VBA here. Almost done with this project I am working on and missing one piece I cant figure out with VBA.
I am using a user form to input data into a sheet. I have a condition that if a column range (I named it) is > 0, take value from another column and use that value to add that many rows to another table on another sheet.
I got all that working great. The roadblock I am having is I also need the row number of the activecell from the source sheet (the one I use the user form with) to also be inserted into column A of all the new rows inserted when the code executes.
I need this done because I have formulas in cells B through E that calculate based on the value in row A; and i need the value in row a to be the row number from the row I just inserted into my source sheet (hens the "active cell" mentality).
Clear as Mud? I hope I explained this all correctly and would really appreciate any help I can get on this. I have provided the code. Its the last part I need help with. I think its a loop I have to use but I haven't used loops in vba yet.
Sub AddRowsToTable()
Dim targetTable As ListObject
Dim valueLastRowLastCol As Long
Set targetTable = Range("TblDateRng").ListObject
' Get last row, last column value
valueLastRowLastCol = Intersect(Rows(ActiveCell.Row), Range("Duration")).Value
'Add as many rows as the number in last column, last row of source table to target table
targetTable.Resize targetTable.HeaderRowRange.Resize(targetTable.ListRows.Count + valueLastRowLastCol
+ 1)
'Execute the column number of the active cell from the source sheet, and places it in column (A) of
new rows added from code above
For Each cell In targetTable.Range("A:A")
If targetTable.Range("A:A") = "" Then
Range("A:A").Value = ActiveCell.Row
MsgBox "Success"
End If
Next
End Sub