0

I have a sheet1 with Like this:

     ColumnA     ColumnB
1    SerialNo.   Smartphones
2                iphone 15
3                iphone 15 pro
4                iphone 15 plus
5                iphone 15 pro max


So I came up with this code that puts a rows count into ColumnA whenever I put a smartphone name in ColumnB

Private Sub 
 Worksheet_SelectionChange(ByVal Target As Range)

Dim count As Long

count=Application.WorksheetFunction.CountA(Sheet1.Range("B:B")

For i = 1 to count
Sheet1.Range("A" & i + 1).Value = i
Next i
End sub

But here it does only if I enter something in columnB ,

Is it possible if I enter something in like any column of this selected sheet ,that put a rowcounts in the ColumnA
?


 


I tried various functions related to the serial number from this site and from others too , but didn't found anything which can put a serial no. If u write something in the smartphones column.

Can anyone know it how to put a serial number automatically, with the VBA code?

9
  • Look into the worksheet_change event. Plenty of examples of that here on SO. Commented Sep 26, 2023 at 20:10
  • 1
    It's unclear where the SerialNo. value is coming from. Is there a table? Commented Sep 26, 2023 at 20:33
  • Exactly where in the worksheet_change? Like here in stackoverflow? Commented Sep 26, 2023 at 20:40
  • No that r just the rows , the serial no column is empty, so serial number has to be given with s vba code Commented Sep 26, 2023 at 20:40
  • What kind of serial numbers? If you have a code that will fill the empty cells with the serial numbers, share it and we'll help you automate it. Commented Sep 26, 2023 at 21:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.