Good morning and happy Friday!
Question: Is there a way to make xlPart and xlWhole variable?
I do not know how to do that so i am attempting to do what you see below.
I am running into an error with this code section below. Error 91: "Object variable or With block variable not set"
I am trying to use Find to locate an exact match or a partial match depending on what my user knows.
When i am not using an IF statement the code works fine...
Only using
Set rngFind = .Find(MyShort, .Cells(1, 1), LookIn:=xlValues, LookAt:=xlWhole)
Here is everything because i am always reading you guys ask that of people
Question: Is there a way to make xlPart and xlWhole variable?
I do not know how to do that so i am attempting to do what you see below.
I am running into an error with this code section below. Error 91: "Object variable or With block variable not set"
Code:
If Sheets("Dashboard").Range("A2").Value = 1 Then
Set rngFind = .Find(MyShort, .Cells(1, 1), LookIn:=xlValues, LookAt:=xlWhole) [COLOR=#00ff00]'Errors here[/COLOR]
Else
Set rngFind = .Find(MyShort, .Cells(1, 1), LookIn:=xlValues, LookAt:=xlPart)
End If
When i am not using an IF statement the code works fine...
Only using
Set rngFind = .Find(MyShort, .Cells(1, 1), LookIn:=xlValues, LookAt:=xlWhole)
Here is everything because i am always reading you guys ask that of people
Code:
Sub GatherAll()
Dim rngFind As Range
Dim rngPicked As Range
Dim rngLook As Range
Dim WhereiGo As Range
Dim strValueToPick As String
Dim strFirstAddress As String
Dim MyShort As String
MyShort = ActiveCell.Value
If ActiveCell.Address = Range("A4") Then
Set rngLook = Sheets("Database").Range(Sheets("Database").Range("D7").End(xlDown).End(xlDown).Offset(0, -3), Sheets("Database").Range("A7"))
ElseIf ActiveCell.Address = Range("B4") Then
Set rngLook = Sheets("Database").Range(Sheets("Database").Range("D7").End(xlDown).End(xlDown).Offset(0, -2), Sheets("Database").Range("B7"))
ElseIf ActiveCell.Address = Range("C4") Then
Set rngLook = Sheets("Database").Range(Sheets("Database").Range("D7").End(xlDown).Offset(0, 2), Sheets("Database").Range("F7"))
End If
With rngLook
If Sheets("Dashboard").Range("A2").Value = 1 Then
Set rngFind = .Find(MyShort, .Cells(1, 1), LookIn:=xlValues, LookAt:=xlWhole)
Else
Set rngFind = .Find(MyShort, .Cells(1, 1), LookIn:=xlValues, LookAt:=xlPart)
End If
If Not rngFind Is Nothing Then
strFirstAddress = rngFind.Address
Set rngPicked = rngFind
Do
Set rngPicked = Union(rngPicked, rngFind)
Set rngFind = .FindNext(rngFind)
Loop While Not rngFind Is Nothing And rngFind.Address <> strFirstAddress
End If
End With
If Not rngPicked Is Nothing Then
Set WhereiGo = Sheets("Dashbaord").Range("A65532").End(xlUp).Offset(1)
rngPicked.Columns("A:B").Copy Destination:=WhereiGo
'Some other columns.copy Destination:=WhereiGo.Offset(0, 3) ...whatever
'Some other columns.copy Destination:=WhereiGo.Offset(0, 12) ...whatever
End If
End Sub