earthworm
Well-known Member
- Joined
- May 19, 2009
- Messages
- 759
- Office Version
- 2019
- 2016
- Platform
- Windows
I Have a workbook that contains data . I created a macro that copy the selected data and paste the same in new workbook . and create serial number as per data pasted on newly created workbook . I tried below macro . But what this is doing is its creating serial number based on previous work book and pasting in newly created workbook . Please help me what am i doing wrong. I even tired to select active workbook select before below code but still there is same issue .
VBA Code:
'Auto fill Serial Number
If WorksheetFunction.CountA(Columns("B:B")) < 2 Then
Range("A2").Value = 1
Else
'To Add serial number if there is more data in column
Dim y As String
y = Sheet1.UsedRange.Rows.Count
Range("A2").Value = 1
Cells(2, 1).AutoFill Destination:=Range("A2:A" & y + 2), Type:=xlFillSeries