Range with .End(xltoleft) problem

Certified

Board Regular
Joined
Jan 24, 2012
Messages
189
Hi

I am trying to write a simple code to count the number of columns in a range. However I am having an issue determining the range.


Code:
Range(Cells(RowCnt, COlcnt).End(xlToLeft).Select

When I run this code, I get a "run-time error '1004."

I can't for the life of me figure out what i am doing wrong.

Please help.

Thanks
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
try the below. 4 represents the row number. change as needed. this will identify the number of columns in your spreadsheet, this can then be used to select the last column if needed
Code:
lc = Cells(4, Columns.Count).End(xlToLeft).Column
 
Upvote 0
Code:
Range(Cells(RowCnt, COlcnt).End(xlToLeft).Select

When I run this code, I get a "run-time error '1004."
Count your opening and closing parentheses... the Cells object has an open/close pair, the End object has an open/close pair, but the Range object only has an open parenthesis... it is missing its close parenthesis.
 
Upvote 0
Count your opening and closing parentheses... the Cells object has an open/close pair, the End object has an open/close pair, but the Range object only has an open parenthesis... it is missing its close parenthesis.


Hi,

I am still getting an error.
 
Upvote 0
I am still getting an error.
Without seeing the rest of your code, it is hard to know the code line you posted is supposed to be doing for your overall procedure. Personally I hate selecting cells just to operate on them (it makes your code sloppy and slow), but looking more closely at what you posted, I am thinking you do not need the Range call at all (unless you left some other references out of it... again, can't know that without seeing the rest of your code), so this may be what you want...

Cells(RowCnt, COlcnt).End(xlToLeft).Select
 
Upvote 0

Forum statistics

Threads
1,196,409
Messages
6,015,104
Members
441,870
Latest member
kojack

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