write at exceltoexplore@gmail.com : Report Automation|Dashboard in Excel| Provide Excel consulting through macro (VBA) automation |Financial Modeling | Ethical Hacking

Wednesday, 13 July 2011

Add Serial Number in Column Automatically

If you want to Add serial no in column A automatically once you enter data in column B then try below code
1. Right click on sheet tab
2. select view code
3. Paste below code in sheet module

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Long
For i = 2 To Cells(Rows.Count, "B").End(xlUp).Row
If Cells(i, "B").Value <> "" Then
Cells(i, "A").Value = i - 1
End If
Next i
End Sub

No comments:

Post a Comment