first enty colomn VBA loop

Sayf1

New Member
Joined
Jul 17, 2018
Messages
8
Hi all,

i created a loop but I have MYCOLOMNas a variable representing where the macro should start. So 1=A B=2 and so on. I was wondering how I change my colomn to start from the first empty colomn and run the macro from there



thank you!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
yeah try this out this assumes you have data in row 1

Code:
Dim lastCol as Long
lastCol = sht.Cells(1, sht.Columns.Count).End(xlToLeft).Column + 1
 
Upvote 0
yeah try this out this assumes you have data in row 1

Code:
Dim lastCol as Long
[COLOR=#00007F]Set[/COLOR] sht = ThisWorkbook.Worksheets("Sheet1")
lastCol = sht.Cells(1, sht.Columns.Count).End(xlToLeft).Column + 1

inserted a line i forgot
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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