Selecting a dynamic range excluding some cells?

TravisB81

New Member
Joined
Apr 12, 2011
Messages
12
I spent some time searching the forums and I have found some posts that I think might be helpful if I understood more about VBA and macro coding. I read a post talking about how it's bad idea to "select" cells when you should be setting them as a range, but that seems more like a codebased thing than a "record macro" style. So I apologize if this question has been handled adnaseum.

I am using windows xp and excel 2007.
I am making a macro that is sorting data by 1 column and then subtotaling and using the subtotals to make graphs. The information I am trying to select is 3 columns and the number of rows changes each week.

I want the macro to select all visible in the range except the last row, which will be a grand total row and make all my graphs look awkward.

I am building this macro with the record macro feature, because I do not know VBA very well. What I was trying to do in my sequence of recording was selecting the 3 columns and then alt + ;, which would select all visible in the 3 selected columns, but that doesn't help me get rid of the grand total row. So I was doing 2 work around macros with some manual work in between. If I could get rid of the grand total row as part of the macro I could have a single macro.

Because I know the answer will come in a coded form, I am hoping that I could copy and paste it into my recorded macro? Would that work?

Thanks :)
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
This will select Visible cells in Cols A:C excluding last row:
Code:
Range("A1:C" & Range("A:C").SpecialCells(xlCellTypeLastCell).Row - 1).SpecialCells(xlCellTypeVisible).Select
 
Upvote 0
If I am starting in the second row of a column range and use CTRL-DownArrow, then Arrow Up when recording a macro, it gives me strange code that does not work in a macro when I am trying to select a range to copy down the formula in the top cell to all blank cells below it, excluding the bottom, border cell which has a " " (blank) character created with the space bar.
When I try to record a relative reference macro to figure out the command to reduce the range by one row, I get a flaky ActiveCell.Range(“A1:A9”).Select, which does not seem to relate to the range I am asking for. Will the code below help me figure out how to adapt the range to meet my requirements? Thanks,

This will select Visible cells in Cols A:C excluding last row:
Code:
Range("A1:C" & Range("A:C").SpecialCells(xlCellTypeLastCell).Row - 1).SpecialCells(xlCellTypeVisible).Select
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

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