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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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,214,920
Messages
6,122,272
Members
449,075
Latest member
staticfluids

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