How do I get a sub-range in VBA

MikeMcCollister

Board Regular
Joined
May 6, 2020
Messages
71
Office Version
  1. 365
Platform
  1. Windows
I have a table called "MainChecking". I can get the range for a column of the table by using the .Range function. Now I want a subset of that range but I can't figure it out. For example, this range may have 500 rows in it with just one column. I want to get a range that will be from row 229 to 236 so I can then search within that subset of the range. I can't figure this out. The best that I can figure is with the line with the comment "UGH! does not work". But it does not work, ugh!

Here is a portion of my code.

VBA Code:
Private Const gCheckingAccountWorksheet As String = "Main Checking"
Private Const gCategoryRange As String = "MainChecking[Category]" ' table column

With ThisWorkbook.Worksheets(gCheckingAccountWorksheet)
    Dim mRowFirst As Long
    Dim mRowLast As Long
    Dim workingRange As Range
    Dim workingSubRange As Range

    mRowFirst = 229 ' value found elsewhere
    mRowLast = 236 ' value found elsewhere
    Set workingRange = .Range(gCategoryRange)
    Set workingSubRange = workingRange.Range(workingRange.Cells(mRowFirst, 1), workingRange.Cells(mRowLast, 1)) ' UGH! does not work

End With

Does anyone have any ideas on how to get this to work?

Thanks,

Mike
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try changing
VBA Code:
Set workingSubRange = workingRange.Range(workingRange.Cells(mRowFirst, 1), workingRange.Cells(mRowLast, 1))
to
VBA Code:
Set workingSubRange = Range(workingRange.Cells(mRowFirst, 1), workingRange.Cells(mRowLast, 1))
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,356
Members
449,080
Latest member
Armadillos

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