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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

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
 

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
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
60,830
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!
 

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!
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,883
Messages
5,766,926
Members
425,386
Latest member
DougFarley

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