Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming Dynamic Range and turning it into a variable

Tags:

excel

vba

I am trying to name a range based on a .Find then define that range as my variable so I can enter the variable into a different function. When I run the code I get a type mismatch error.

Sub Faked()
Dim r As Range
Cells.Find(What:="EE status", After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Activate
    Range(Selection, Selection.End(xlDown)).Name = "Win"
Set r = ("Win")


End Sub
like image 306
TonyP Avatar asked Dec 12 '25 08:12

TonyP


1 Answers

Because Scott says so. Try Set r = range("Win")

To test if r picked up the range correctly, one could do

for each c in r
    debug.print c
next

Edit: or if you're cool like Dirk,

Set r = [Win]
like image 94
findwindow Avatar answered Dec 15 '25 15:12

findwindow