• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Please Guide For my Code to run a micro for auto numbring

Hello Everybody,

I have write a little code for auto numbering in my sheet.The Sheet name is sheet 1 and the column are selected for the code is A and B.

Code:
Sub mylastcell()


      Cells(Rows.Count, 1).End(xlUp).Select
 
 
 
For i = 0 To 5
ActiveCell(i, 1).Offset(2, 0) = i + 1
Next i
End Sub

I required some help to modify my code in such a way that when i enter data in column B starting from row 3,the serial no should appear automatically in column A as per entry of column B.
I used the For loops i=0 to 5 but want it for unlimited rows.Please let me help .
 

Attachments

  • autoNum.xlsm
    14.7 KB · Views: 4
Paste the following code in the Sheet Level Module :

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim lastRow As Long
    lastRow = Range("B" & Rows.Count).End(xlUp).Row
    Range("A3").AutoFill Destination:=Range("A3:A" & lastRow), Type:=xlFillSeries
End Sub

Also, you must enter the first serial number in A3 for the above macro to
work for all other entries.
 
Hi !
when i enter data in column B starting from row 3,the serial no should appear automatically in column A as per entry of column B.
So you must paste next code in the worksheet module only :​
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 2 And Target.Row > 2 Then Target(1, 0).Value = Target.Row - 2
End Sub
Do you like it ? So thanks to click on bottom right Like !
 
Paste the following code in the Sheet Level Module :

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim lastRow As Long
    lastRow = Range("B" & Rows.Count).End(xlUp).Row
    Range("A3").AutoFill Destination:=Range("A3:A" & lastRow), Type:=xlFillSeries
End Sub

Also, you must enter the first serial number in A3 for the above macro to
work for all other entries.
Thanks for your reply but the code gives me error.
 
Hi !

So you must paste next code in the worksheet module only :​
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 2 And Target.Row > 2 Then Target(1, 0).Value = Target.Row - 2
End Sub
Do you like it ? So thanks to click on bottom right Like !
Yes... its ok now.Thanks for your nice support
 
Back
Top