Easy For loop not working

MattH1

Board Regular
Joined
Jul 15, 2016
Messages
174
Hey everyone. I have the following lines of code:

Code:
Sub Ones()

Dim RowCount As Long
Dim ColumnCount As Long

'Counts the number of rows within
RowCount = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
ColumnCount = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column

For i = 2 To i = RowCount
    Cells(i, ColumnCount + 1).Value = "1"
Next I

End Sub

It's a very simple VBA code which I want to expand on, but I'm unsure why I run the program and it doesn't generate any values. If it helps, my current code has 25 columns and 1000 Rows (but RowCount and ColumnCount work). I just want to know what exactly is wrong with my For loop.
 
Last edited:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
You need to tell us what your wanting to do here.

And you said:
"It's a very simple <acronym title="visual basic for applications">VBA</acronym> code which I want to expand on"

We would need to see all your code and a explanation what your wanting to do.
 
Upvote 0
Hi "My Aswer Is This",
I'm just looking to have the code output the letter 1 in the NEXT column all the way to the bottom of my sheet (until RowCount, which would be Row 25 in my sample data set).
My code is 25x25 so I would want this to become 25x26. I have the column header code below:

Code:
'Column header
Cells(1, ColumnCount + 1).Value = "DUMMY VARIABLE"

I know how to expand it but I am having trouble getting this simple part of it to work. When I run this, it does not output 1 in the 2nd to 25th row of the 26th column (which is what I believe that loop should be doing.)
 
Last edited:
Upvote 0
Hey everyone. I have the following lines of code:

Code:
Sub Ones()

Dim RowCount As Long
Dim ColumnCount As Long

'Counts the number of rows within
RowCount = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
ColumnCount = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column

For i = 2 To [B][COLOR="#FF0000"]i = RowCount[/COLOR][/B]
    Cells(i, ColumnCount + 1).Value = "1"
Next I

End Sub

It's a very simple VBA code which I want to expand on, but I'm unsure why I run the program and it doesn't generate any values. If it helps, my current code has 25 columns and 1000 Rows (but RowCount and ColumnCount work). I just want to know what exactly is wrong with my For loop.
Did you mean the part I highlighted in red to be I + RowCount instead? It looks like you pressed the correct key (=/+) but forgot to hold down the Shift Key while doing it.
 
Last edited:
Upvote 0
Did you mean the part I highlighted in red to be I + RowCount instead?

No I want it to stop at RowCount and I'm guessing that's my mistake.... It should just be RowCount not I = RowCount.

That fixed it, thank you! Time to slowly waddle away in shame!!!!
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,539
Members
449,088
Latest member
RandomExceller01

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