Counter

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,059
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
my below code gives me output as ES1 and the counter is not working as output ES1, ES2, ES3 and so on. I am not sure what is wrong.

Code:-
Private Sub CommandButton1_Click()
Dim i As String, e As String
i = 1
e = "ES"
Set Rng = Sheets("sheet1").Cells(Rows.Count, 3).End(xlUp).Offset(1, 0)
For Each Cell In Rng
Cell.Value = e + i
i = i + 1
Next Cell
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi,
a counter varible must be either long, integer varible but not a string...
and you did not declare the rng either..
dim rng as range
 
Last edited:
Upvote 0
There is only one cell in rng :
Set Rng = Sheets("sheet1").Cells(Rows.Count, 3).End(xlUp).Offset(1, 0)
 
Upvote 0
did tried bu no luck

Code:-
Dim i As Long, e As String, rng As Range
i = 1
e = "ES"
Set rng = Sheets("sheet1").Cells(Rows.Count, 3).End(xlUp).Offset(1, 0)
For Each Cell In rng
Cell.Value = e + i
i = i + 1
Next Cell
 
Upvote 0
still when you are using an object varible and you are setting it then you need to have this object varible first declared..

I am just about to head out so hope you get it sorted...

Cheers
 
Upvote 0
sorry

Yes, thanks correct as the rng will add the details in the next cell of column "C"
 
Upvote 0

Forum statistics

Threads
1,215,011
Messages
6,122,677
Members
449,092
Latest member
tayo4dgacorbanget

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