Run-time error '91' Object variable or With block variable not set

mrnacar

Board Regular
Joined
Jan 27, 2010
Messages
188
Office Version
  1. 365
Platform
  1. Windows
Can someone tell me how to fix my macro? I get the "title" error at the following code:

Code:
    Selection.Find(What:=eod, After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Select

Here is my macro:

Code:
Sub hardcode()
Dim eod As String
eod = Range("A1").Value
Dim Response As Integer
      Response = MsgBox(prompt:="Selecting 'Yes' will hard code " & "'" & eod & "' values.", Buttons:=vbYesNo)
      If Response = vbNo Then Exit Sub
      If Response = vbYes Then
'Hard Code Portfolio Actual
    Range("B11:M11").Select
    Selection.Find(What:=eod, After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Select
    ActiveCell.Offset(1, 0).Select
    ActiveCell.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    ActiveCell.Offset(0, 1).FormulaR1C1 = _
        "=ROUND(+'\\10.10.10.205\alco\ALCO2011\Production forecast2011\[MCFCST11.xls]ACTUAL VS. FORECAST'!R8C8/1000,0)"
'Hard Code Tamuning Actual
    Range("B18:M18").Select
    Selection.Find(What:=eod, After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Select
    ActiveCell.Offset(1, 0).Select
    ActiveCell.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    ActiveCell.Offset(0, 1).FormulaR1C1 = _
        "=ROUND('\\10.10.10.205\alco\ALCO2011\Production forecast2011\[MCFCST11.xls]ACTUAL VS. FORECAST'!R6C8/1000,0)"
    
'Hard Code Dededo Actual
    Range("B23:M23").Select
    Selection.Find(What:=eod, After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Select
    ActiveCell.Offset(1, 0).Select
    ActiveCell.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    ActiveCell.Offset(0, 1).FormulaR1C1 = _
        "=ROUND('\\10.10.10.205\alco\ALCO2011\Production forecast2011\[MCFCST11.xls]ACTUAL VS. FORECAST'!R7C8/1000,0)"
End If
Range("B1").Select
End Sub
 
Thank you.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
If you step through the code using the F8 key then it will stop at the line that contains the error.

Might help getting to the point quicker.

Its obviously the ''eod'' bit, maybe you have to use "set".
You have not even declared ''eod'' as any sort of variable, beside string which I doubt will let it work as a range.
 
Last edited:
Upvote 0
Got it. It couldn't find the string at the range because it was looking in formulas instead of value.

Thanks though.
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,865
Members
452,948
Latest member
UsmanAli786

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