Columns.Count

KaibleBasha

New Member
Joined
Aug 8, 2014
Messages
36
Hi

I am trying to switch from counting Rows to counting columns in VBA and something isn't quite right.
This is what I have come up with (including comments for explanation)



Sub Faffing_Around()


Dim newCol As Integer
newCol = Cells(1, Columns.Count).End(xlLeft).Column + 1


'I have row one of three columns populated and need to automatically add new columns onto the end of this
'I frequently use this to count my rows and add another row after finding the last row & it works fine.
'e.g. of row count
'newRow = Cells(Rows.Count, "A").End(xlUp).Row + 1


'Columns.Count above = 16384


End Sub




Can you see where I am going wrong as I keep getting an application definied or Object defined error.

Thanks
Kai
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi,

Rich (BB code):
Dim newCol As Long
newCol = Cells(1, Columns.Count).End(xlToLeft).Column + 1
 
Upvote 0

Forum statistics

Threads
1,214,547
Messages
6,120,139
Members
448,948
Latest member
spamiki

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