LJIII
LJIII

Reputation: 1

Using cell contents to set a range variable

I'm trying to run code on a range that changes through different iterations of a loop. Here is what I would like the code to run if the value in range("SearchBy") = ZeroCounts

Dim WorkRange As range
Set WorkRange = range("ZeroCounts")

Here is how I am attempting to solve this but I can't find a way that works without returning errors. Any ideas?

Dim dummy As String
dummy = """" & range("SearchBy").Value & """"

Dim WorkRange As range
WorkRange = Sheets("HungarianAlgorithm").range(dummy)

WorkRange.Select

Upvotes: 0

Views: 34

Answers (1)

Tim Williams
Tim Williams

Reputation: 166146

You need to use Set when assigning a value to an object-type variable

Try

Set WorkRange = Sheets("HungarianAlgorithm").Range(Range("SearchBy").Value)

Upvotes: 1

Related Questions