VBA - Hard Coded to Cell Reference

itsgrady

Board Regular
Joined
Sep 11, 2022
Messages
132
Office Version
  1. 2021
Platform
  1. Windows
  2. MacOS
In the bold area, I would like to make a cell references instead of hard coding. Is this possible to have about 10 cells VBA will reference instead of the actual criteria in the code? The criteria changes a lot more than what was first mentioned when the VBA code was built.

Sub SpecialDMann()

Dim ws As Worksheet

Set ws = ThisWorkbook.Sheets("VPI-All-WhsRpt")

Application.ScreenUpdating = False
If ws.AutoFilterMode Then
ws.AutoFilterMode = False

End If

Sheets("VPI-All-WhsRpt").Activate

ws.ListObjects("VPI_All_WhsRpt").AutoFilter.ShowAllData

ws.ListObjects("VPI_All_WhsRpt").Range.Select

ws.ListObjects("VPI_All_WhsRpt").Range.AutoFilter 22, Array("4A Back", "4B Back", "4C Back", "4D Back", "4A Middle", "4B Middle", "4C Middle"), Operator:=xlFilterValues

Set rng = ws.Range("A10")
rng.Select
rng.Application.Goto rng, True
Set rng = Nothing
Set ws = Nothing

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Check out this link on a similar question, creating an array from a range to use in a Filter in VBA.

And another article which may help:
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

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