Insert Auto Serial Number Using Vba
Insert Auto Serial Number Using Vba
Quick access
Ashidacchi I want to insert auto serial no. in Column A of Sheet2. First row can be ignored as I am using that as
Joined Jun 2007 Header. Serial No will be assigned based on the last row of B Column.For example, If B10 is the last
Ashidacchi's threa… 0 used cell in Sheet2 then Serail number would be 1-9 starting from A2 to A10. I want to achieve this by
3 5 15 Show activity
Sign in clicking on a command button which is present in Sheet1. Also is it possible to have 'All Border' upto
to
vote last cell of B Column? Means, if B12 is the last used cell in Sheet2 then I want to have 'All Border' in
A1:B12.
Thanks..
Answers
Here's my sample code.
0 [VBA sample]
Sign in
to
vote Private Sub CommandButton1_Click()
Dim LastRow As Integer
Dim idx As Integer
Worksheets("Sheet2").Activate
LastRow = ActiveSheet.Range("B2").End(xlDown).Row
For idx = 1 To LastRow - 1
Worksheets("Sheet2").Cells(idx + 1, 1).Value = idx
Next
End Sub
[image of sheets]
For i = 7 To 12
.Range(.Range("a2"), rLastCell).Borders(i).LineStyle = xlContinuous
Next i
End With
End Sub
Best Regards,
Asadulla Javed, Kolkata
---------------------------------------------------------------------------------------------
Please do not forget to click “Vote as Helpful” if any post helps you and "Mark as Answer”if it
solves the issue.
For i = 7 To 12
.Range(.Range("a1"), _
rLastCell.Offset(, 1)).Borders(i).LineStyle = xlContinuous
Next i
End With
End Sub
It does what you need
Best Regards,
Asadulla Javed, Kolkata
---------------------------------------------------------------------------------------------
Please do not forget to click “Vote as Helpful” if any post helps you and "Mark as Answer”if it
solves the issue.
All replies
Here's my sample code.
0 [VBA sample]
Sign in
to
vote Private Sub CommandButton1_Click()
Dim LastRow As Integer
Dim idx As Integer
Worksheets("Sheet2").Activate
LastRow = ActiveSheet.Range("B2").End(xlDown).Row
For idx = 1 To LastRow - 1
Worksheets("Sheet2").Cells(idx + 1, 1).Value = idx
Next
End Sub
[image of sheets]
For i = 7 To 12
.Range(.Range("a2"), rLastCell).Borders(i).LineStyle = xlContinuous
Next i
End With
End Sub
Best Regards,
Asadulla Javed, Kolkata
---------------------------------------------------------------------------------------------
Please do not forget to click “Vote as Helpful” if any post helps you and "Mark as Answer”if it
solves the issue.
Hi Asadulla,
It's very nice to have your code. It;s working exactly as I mentioned above. Only one question I have
i.e. is it possible to have 'All border' in C Column also? At the time of clicking the button from Sheet
0 I have value in only B Column of Sheet2 But I want to have 'All Border' in A,B,C Column upto last
Sign in used cell of B Column.
to
vote
Thank you.
For i = 7 To 12
.Range(.Range("a1"), _
rLastCell.Offset(, 1)).Borders(i).LineStyle = xlContinuous
Next i
End With
End Sub
It does what you need
Best Regards,
Asadulla Javed, Kolkata
---------------------------------------------------------------------------------------------
Please do not forget to click “Vote as Helpful” if any post helps you and "Mark as Answer”if it
solves the issue.