Help needed combining a few simple macros

kwp004

Board Regular
Joined
Dec 27, 2016
Messages
93
I want to do two things:

1) rather than have the range end at AB605, have it go to the last cell in AB that contains data
2) Combine these three macros into one, conditional on the value that's in cell B2 (so if B2="A", run the first macro, if B2="B", run the second, if B2="C", run the third.


Sub AllOpps()

Range("A4:AB605").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Sheets("Filters").Range("A1:B3"), Unique:=False

End Sub

Sub ActiveOpps()

Range("A4:AB605").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Sheets("Filters").Range("A1:AB3"), Unique:=False

End Sub

Sub ClosedOpps()

Range("A4:AB605").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Sheets("Filters").Range("A7:M9"), Unique:=False
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
How about

VBA Code:
Sub Macros()
  Dim lr As Long, rng As String
  lr = Range("AB" & Rows.Count).End(3).Row
  Select Case Range("B2")
    Case "A": rng = "A1:B3"
    Case "B": rng = "A1:AB3"
    Case "C": rng = "A7:M9"
  End Select
  Range("A4:AB" & lr).AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Sheets("Filters").Range(rng)
End Sub
 
Upvote 0
You are my hero!!

How should it be changed if I want to also go to the last row that contains data? Basically, do the equivalent of CTRL + A, if your data starts in cell A4.
 
Upvote 0
The code does that now !
Change the reference to col "A"
VBA Code:
lr = Range("A" & Rows.Count).End(3).Row
OR if you aren't sure which col has the most data use...
VBA Code:
lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
 
Upvote 0
have it go to the last cell in AB that contains data

Your comment is about the last row with data from column AB.
But if you want to take column A as a reference, then you can change the column to A, as commented by Michael.

VBA Code:
lr = Range("A" & Rows.Count).End(3).Row

Or also, without considering a column
VBA Code:
lr = Activesheet.range("A:AB").Find("*", , xlValues, , xlRows, xlPrevious).Row
 
Upvote 0
@DanteAmor
Sorry Dante
Didn't mean to jump your thread, but you didn't appear to be online....I'll leave it to you....:giggle::giggle:
 
Upvote 0
Do not worry. I really appreciate your help, all contributions are welcome. ?
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,213,537
Messages
6,114,216
Members
448,554
Latest member
Gleisner2

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