Generate a next number

rajkumar.shukla

Board Regular
Joined
Oct 10, 2012
Messages
100
Hi frnds,

I want a simple vba for generate a next number in below the cell. for example. if I enter any data in B1, than vba generate automatically 1 in A1 cell than i enter a data in cell b2 vba generate a next number (ie 2) in cell A2.
 
Hi this code run perfectly. but one thing which is not correct. It start with A1. in row 1 contain my heading. I want this code run from the row 2
Give this a try instead...
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 2 [B][COLOR="#0000FF"]And Target.Row > 1[/COLOR][/B] Then
        Application.EnableEvents = False
        Cells(Target.Row, 1).Value = Target.Row
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Give this a try instead...
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 2 [B][COLOR=#0000FF]And Target.Row > 1[/COLOR][/B] Then
        Application.EnableEvents = False
        Cells(Target.Row, 1).Value = Target.Row
        Application.EnableEvents = True
    End If
End Sub

this code also start with number 2. In row one my heading is there. now I want number start from 1 but in row row. this code generate number 2 in row 2.
 
Upvote 0
Give this a try instead...
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 2 Then
        Application.EnableEvents = False
        Cells(Target.Row, 1).Value = Target.Row[B][COLOR="#FF0000"][SIZE=2] - 1[/SIZE][/COLOR][/B]
        Application.EnableEvents = True
    End If
End Sub
this code also start with number 2. In row one my heading is there. now I want number start from 1 but in row row. this code generate number 2 in row 2.
Sorry, remember, this is not my code... I changed the wrong thing. Try making the change I show in red above.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,038
Messages
6,122,798
Members
449,095
Latest member
m_smith_solihull

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