Multiple range selection using LR

samahiji

Board Regular
Joined
Oct 6, 2015
Messages
82
Office Version
  1. 2019
Platform
  1. Windows
Hello
The code below showing error when selecting multiple columns when defining the last filtered cell (LR).

VBA Code:
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("A1:P" & LR).SpecialCells(xlCellTypeVisible).Select
ActiveSheet.Range("$A$1:$BZ$" & LR).AutoFilter Field:=72, Criteria1:=Array( _
        "WR"), Operator:= _
        xlFilterValues
ActiveSheet.Range("$A$1:$BZ$" & LR).AutoFilter Field:=53, Criteria1:= _
        "BMB"
    ActiveSheet.Range("$A$1:$BZ$" & LR).AutoFilter Field:=54, Operator:= _
        xlFilterAutomaticFontColor
        
    Range("A1:A & LR, AE1:AF & LR").Select
    Range("A1:A & LR, AE1:AF & LR, AV1:AW & LR").Select
    Range("A1:A & LR, AE1:AF & LR, AV1:AW & LR, BQ1:BT & LR").Select
    Selection.Copy
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
The important thing to remember when using variables to build ranges is:
- all literal text needs to be between double-quotes
- all variables need to be OUTSIDE of the double-quotes
- you join all the pieces using "&"

You did it fine here:
Rich (BB code):
Range("A1:P" & LR).SpecialCells(xlCellTypeVisible).Select
but not here:
Rich (BB code):
    Range("A1:A & LR, AE1:AF & LR").Select
    Range("A1:A & LR, AE1:AF & LR, AV1:AW & LR").Select
    Range("A1:A & LR, AE1:AF & LR, AV1:AW & LR, BQ1:BT & LR").Select

The first one should look like this:
VBA Code:
    Range("A1:A" & lr & ", AE1:AF" & lr).Select
and the rest should follow the same pattern.
 
Upvote 1
Solution

Forum statistics

Threads
1,216,728
Messages
6,132,377
Members
449,723
Latest member
Ghufran

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