Select range between last row in a-column and last column in b-column.

NichoD

Board Regular
Joined
Jul 31, 2022
Messages
54
Office Version
  1. 2016
Platform
  1. Windows
Hello, I am fairly new to VBA.

I have a long list filled with values where some are blanks. I want to select a range between the last value found in A-column, for example A300 and the last value found in B-column, for example B320.

So far my code is:

Dim IRow As Long
Dim ICol As Long
Dim rng As Range

IRow = Cells(1, Rows.Count).End(xl).End(xlUp).Row
ICol = Cells(2, Columns.Count).End(xlToLeft).Column

I wonder how I should code rng to select all values between A300 and B320.

Thanks in advance.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Welcome to the Board!

Not sure why you are trying to find the last column. That doesn't seem to have anything to do with your question.
Here is one way to do what you want:
VBA Code:
Sub Test()

    Dim lrA As Long
    Dim lrB As Long
    
'   Find last row in column A with data
    lrA = Cells(Rows.Count, "A").End(xlUp).Row
    
'   Find last row in column B with data
    lrB = Cells(Rows.Count, "B").End(xlUp).Row
    
'   Select range in columns A and B after last row of A down to last row of B
    Range(Cells(lrA + 1, "A"), Cells(lrB, "B")).Select
    
End Sub
 
Upvote 0
Solution
Welcome to the Board!

Not sure why you are trying to find the last column. That doesn't seem to have anything to do with your question.
Here is one way to do what you want:
VBA Code:
Sub Test()

    Dim lrA As Long
    Dim lrB As Long
   
'   Find last row in column A with data
    lrA = Cells(Rows.Count, "A").End(xlUp).Row
   
'   Find last row in column B with data
    lrB = Cells(Rows.Count, "B").End(xlUp).Row
   
'   Select range in columns A and B after last row of A down to last row of B
    Range(Cells(lrA + 1, "A"), Cells(lrB, "B")).Select
   
End Sub
Thank you so much! This is what i have been looking for!

Kind regards.
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

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