Really Easy Question - Populating cells by row

I'm rubbish with Excel

Board Regular
Joined
Nov 18, 2003
Messages
52
I know this is a really easy request, but I've completely drawn a blank.

Basically, I want a macro the same as below, but populating cells A1 - E1 (last blank column) rather than A1 - A5 (last blank row.)

lastrow = Range("A65536").End(xlUp).Row + 1

for i = 1 to lastrow
Range("a" & i).Value = i
next i

I know it's simple, but I've gone stupider than normal.

thanks in advance
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Is this what you want?

Code:
Sub PopulateColumns()

    lngLastCol = Range("IV1").End(xlToLeft).Column + 1

    For i = 1 To lngLastCol
        Cells(1, i) = i
    Next i

End Sub
 
Upvote 0
lastcol = Range("IV1").End(xlToLeft).Column + 1
For i = 1 To lastcol
Cells(1, i).Value = i
Next i
 
Upvote 0
BTW, what are you hoping to accomplish by this code?

It simply seems to renumber all the cell values in the column all the way over to the last populated column in that row, plus one more. It will wipe out the previous cell contents.

Maybe that is what you are intending to do, it just seems a little odd!
 
Upvote 0
Thanks everyone for your help.

jmiskey, I'm actually working on something which would've been a lot harder to explain. I can use the solutions given and adapt them.

Thanks again, everyone!
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,986
Members
448,538
Latest member
alex78

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