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

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

dk

MrExcel MVP
Joined
Feb 15, 2002
Messages
2,942
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

CraigM

Active Member
Joined
Feb 27, 2003
Messages
320
lastcol = Range("IV1").End(xlToLeft).Column + 1
For i = 1 To lastcol
Cells(1, i).Value = i
Next i
 
Upvote 0

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
66,509
Office Version
  1. 365
Platform
  1. Windows
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

I'm rubbish with Excel

Board Regular
Joined
Nov 18, 2003
Messages
52
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,186,365
Messages
5,957,443
Members
438,306
Latest member
Crystal_Blue

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
Top