VBA To Create auto Serial number based on row of newly created sheet data

earthworm

Well-known Member
Joined
May 19, 2009
Messages
759
Office Version
  1. 2019
  2. 2016
Platform
  1. 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
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,214,424
Messages
6,119,404
Members
448,893
Latest member
AtariBaby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top