Counting certain cells in a row on excel macro

spiffmonkey1

New Member
Joined
Jun 23, 2011
Messages
41
Hi,

I want to count certain cells in a column that have format for example border 1x thick or etc. I've been trying to use ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormulas) but I don't know how to specify "UsedRange" to the range of the row that I want. This function is suppose to return a value or object but it doesn't work on my macro where the variable equals the formula above.

Thanks
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
You could use

Code:
activesheet.rows(10).specialcells(xlcelltypeformulas)
but I don't think that will help you count cells with a certain border format.
 
Upvote 0
Didn't work :/
Basically I'm doing this because I want to make a macro that goes from a column number to the end of the last column(that has text or some format) so that the macro will not apply to empty columns. The macro only applies to one row. I want the variable to go from a column number(which I know how do) to the cell count of the number of cells in the row with anything but blank.

Thanks again
 
Upvote 0
So you want to know the column number of the last cell with data in it in a given row?

Code:
lastCol = cells(myRow,columns.count).end(xltoleft).column.

ought to do this.

or if you want the range:

Code:
set myRange = range(cells(myRow,startCol), cells(myRow,columns.count).end(xltoleft))
 
Upvote 0
So you want to know the column number of the last cell with data in it in a given row?

Code:
lastCol = cells(myRow,columns.count).end(xltoleft).column.

ought to do this.

or if you want the range:

Code:
set myRange = range(cells(myRow,startCol), cells(myRow,columns.count).end(xltoleft))

Awesome works perfectly!! Your a genius! But can you expain what .end(xltoleft) does? Thanks!!
 
Upvote 0
I also want you know if we can use the method above but instead count the last column that has a format like color or border.
Thanks
 
Upvote 0
I'm trying to use this-
FinalColumn = Range(Cells(70, "D"), Cells(70, Columns.Count).End(xlToRight)).Column
Because I want to get the count cell BEFORE the blank cell in the row
However, i don't know why its not working
I also tried-
FinalColumn = Range(Cells(70, "D"), Cells(70, Columns.Count).End(xlToRight)).Row
But I have to add numbers to FinalColumn to make it fit the count cell of the column before the blank cell
 
Upvote 0
Fixed it by doing-
FinalColumn = Range(Cells(70, "A"), Cells(70, "AIU").End(xlToLeft)).Count
Setting the range from A to basically infinity instead of using columns.count
 
Upvote 0
Sorry I didn't get back to you sooner - looks like you figured it out for yourself.

For the record, and you probably aready figured this, but end(xltoleft) is the equivalent of putting your cursor in a cell, holding ctrl and pressing the left arrow. So using columns.count means you're starting from the rightmost column.
 
Upvote 0

Forum statistics

Threads
1,224,542
Messages
6,179,421
Members
452,913
Latest member
JWD210

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