Row address when cell is filled

KestutisTower

New Member
Joined
Jun 2, 2022
Messages
23
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone. I'm looking for a vba code to fill column "C" with row address when data is entered in column "A". And when I delete a row , they would change accordingly. Data is entered automatically via userform.

Before row deleted:
Book1
ABC
1nameproductrow number
2Johnapple2
3Lindaplum3
4Peterapple4
Sheet1

After :
Book1
ABC
1nameproductrow number
2Johnapple2
3Peterapple3
Sheet1
 

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.
The easiest way is likely to have your VBA enter the following formula into column C at the same time it adds data in column A and B:
=if(A2<>"",ROW(),"")
This way it will update the row numbers as you delete rows.

So your VBA might look something like:
VBA Code:
range("C2").formula = "=if(A2<>"",ROW(),"")"
 
Upvote 0
Thanks @Candyman8019 for quick respond. I have tried to adjust and add this line of code to mine, but with no success. My submit code is:
VBA Code:
Sub Submit() 

   Dim sh As Worksheet
   Dim iRow As Long
   Dim eur As String
   eur = ChrW(8364)
   
   Set sh = ThisWorkbook.Sheets("Pardavimai")
   iRow = [Counta(Pardavimai!B:B)] + 1
   
   With sh
      
       
       .Cells(iRow, 1) = UserForm1.txtKlientas.Value
       
       .Cells(iRow, 2) = UserForm1.txtPreke.Value
       
       .Cells(iRow, 3) = UserForm1.txtKiekis.Value
       
       .Cells(iRow, 4) = UserForm1.txtKomentaras.Value
       
       .Cells(iRow, 5) = Val(UserForm1.txtVienetoKaina) * Val(UserForm1.txtKiekis.Value)
       
       .Cells(iRow, 6) = UserForm1.txtVienetoKaina.Value
       
       .Cells(iRow, 10) = UserForm1.txtPreke.Value & "   " & UserForm1.txtKiekis.Value & " vnt." & "   " & UserForm1.txtKomentaras.Value & " - " & Val(UserForm1.txtVienetoKaina) * Val(UserForm1.txtKiekis.Value) & eur
       
       .Cells(iRow, 11) = [Text(Now(), "MM-DD-YYYY")]
       
                  
   End With
   
   
End Sub

the row number would have to go in column 12 ("L"), in the last row.
 
Upvote 0
I haven’t tested but try something like this:
.cells(iRow, 12).formula = "=if(A” & iRow & ”<>"",ROW(),"")"
 
Upvote 0

Forum statistics

Threads
1,215,657
Messages
6,126,057
Members
449,284
Latest member
fULMIEX

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