Counter

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,132
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 can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
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,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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