VBA - Hard Coded to Cell Reference

itsgrady

Board Regular
Joined
Sep 11, 2022
Messages
115
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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
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,215,072
Messages
6,122,968
Members
449,095
Latest member
Mr Hughes

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