Range Question

ummjay

Board Regular
Joined
Oct 1, 2010
Messages
193
hi! I have a sheet which contains content in cells A1:H3, row 4 & 5 is blank, and row 6 starts a new table A6:H9.

I was trying to declare a range for A1:H last. In the event the top table 1 row, or 2, or 3, I wanted to have the range select the last row. doesnt appear to be working properly:

HeaderHeaderHeaderHeaderHeaderHeaderHeaderHeader
xxxxxxxx
xxxxxxxx
HeaderHeaderHeaderHeaderHeader
xxxxxxx
xxxxxxx
xxxxxxx

Set rng = Range("A1", Range("H" & Rows.Count).End(xlUp))

how do i get it to stop in between the two table? Seems it grabs both, and ends at the end of the last table.
 

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)
As long as your table has at least one row of data in it, and every line with data has someething in column A, you can use:
VBA Code:
Dim lr as Long
lr = Range("A1").End(xlDown).Row
Set rng = Range("A1:H" & lr)
 
Upvote 0
hi! I have a sheet which contains content in cells A1:H3, row 4 & 5 is blank, and row 6 starts a new table A6:H9.

I was trying to declare a range for A1:H last. In the event the top table 1 row, or 2, or 3, I wanted to have the range select the last row. doesnt appear to be working properly:

HeaderHeaderHeaderHeaderHeaderHeaderHeaderHeader
xxxxxxxx
xxxxxxxx
HeaderHeaderHeaderHeaderHeader
xxxxxxx
xxxxxxx
xxxxxxx

Set rng = Range("A1", Range("H" & Rows.Count).End(xlUp))

how do i get it to stop in between the two table? Seems it grabs both, and ends at the end of the last table.
VBA Code:
Private Sub subGetRange()
Dim rng As Range

    Set rng = ActiveSheet.Range("A1").CurrentRegion

    ' This will set the range to the first block of data.

End Sub
 
Upvote 0
Solution
VBA Code:
Private Sub subGetRange()
Dim rng As Range

    Set rng = ActiveSheet.Range("A1").CurrentRegion

    ' This will set the range to the first block of data.

End Sub
Oh yeah, forgot about CurrentRegion!
That is probably an easier and more foolproof option, as long as you have at least one completely blank row between the tables!
 
Upvote 0
current region worked! how do i get it to ignore columns I and J? I don't want that included in the range.
 
Upvote 0
Project creep!!

We didn't know that you had more columns. :)

VBA Code:
Private Sub subGetRange()
Dim rng As Range

    With ActiveSheet.Range("A1").CurrentRegion
        Set rng = .Resize(.Rows.Count, 8)
    End With
    
End Sub
 
Upvote 0
current region worked! how do i get it to ignore columns I and J? I don't want that included in the range.
Just amend it to:
VBA Code:
Set rng = Intersect(ActiveSheet.Range("A1").CurrentRegion, Range("A:H"))
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,187
Members
452,616
Latest member
intern444

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