Hi, at the moment I have a macro that is assigned to a button. When clicked, it creates a newline, create and copy a column in another sheet. This code works fine
Sub Insert_Site()
Application.ScreenUpdating = False
Current_row = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row
ActiveSheet.Range("C" & Current_row).Select
current_num = Range("S" & Current_row + 1).Value
ActiveCell.EntireRow.Insert
Range("S" & Current_row + 2).Value = current_num + 1
Application.ScreenUpdating = True
ActiveWorkbook.Sheets(" WAN_OPT_Site_Specification").Activate
Dim LastCol As Long
Application.ScreenUpdating = False
Columns(5).EntireColumn.Hidden = False
'Find last available column
LastCol = Cells(1, "V").End(xlToLeft).Column + 1
Columns(5).Copy
Cells(1, LastCol).Insert xlToLeft
Cells(1, LastCol).PasteSpecial xlValue
Columns(5).EntireColumn.Hidden = True
Application.CutCopyMode = False
Application.ScreenUpdating = True
ActiveWorkbook.Sheets("Sites_WAN_Carriage").Activate
End Sub
What I now want to do is make a cell called "Total Number of Sites" and allow user to input data into "D3" manualy. eg if 3 sites, user input 3 in D3 so D3 = 3.
Since total number of sites = 3, Instead of clicking that button I made 3 times, I want to call the macro 3 times using a nother button.
However it doesn't work.
This is what I used
Sub Generate_Sites()
Target.Address = "$D$3"
Dim rng As Range, cnt As Integer, x
Set rng = Range("D3")
cnt = rng
For x = 1 To cnt
Call Insert_Site
Next x
End Sub
Any help is appriciated
Bookmarks