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

LMjdm

New Member
Joined
Oct 20, 2014
Messages
38
So basically I am at the final stages of creating an excel spreadsheet that generates the fiscal month based on the date give and will assign different tasks to various groups based on the day. I am almost finished the calendar portion but am having a problem in this section
Code:
'Below is the section for finding the current day and highlighting it
Dim whatsToday As Integer 'day value for today
Dim currentFiscalMonth As Integer 'whether it is fiscal date of current month or next month
Dim actualMonth As Integer 'regardless of fiscal month, this generates actual month
whatsToday = Sheets("Master Dial").Range("L2") 
currentFiscalMonth = Sheets("Master Dial").Range("m2")
actualMonth = Sheets("Master Dial").Range("L1")
 
If actualMonth = currentFiscalMonth Then 'if both fiscal and actual month are the same, highlighted day will be after the 1st
    
    Sheets("Master Dial").Range("G4:H4, B6:H6, B8:H8, B10:H10, B12:B12").Find(whatsToday).Select
    ActiveCell.Interior.ColorIndex = 6
    
Else 'if both fiscal and actual month are the same, highlighted day will be before the 1st
    
    If Sheets("Master Dial").Range("b4") <> 1 Then
    Sheets("Master Dial").Range("B4:H4").Find(whatsToday).Select
    ActiveCell.Interior.ColorIndex = 6
    End If
End If
I get the error listed in the title and I don't understand why. Basically this portion of the code is going to look through the calendar and find the date based on what the current day is, and simply highlight it to mark it as "today" the reference is correct (L2). Meaning that I have a cell with the value of todays date and that cell is ALWAYS correct. So I know that's not the issue. The line I believe the error is occurring on is "Sheets("Master Dial").Range("G4:H4, B6:H6, B8:H8, B10:H10, B12:B12").Find(whatsToday).Select" For this example, please assume that whatsToday = 26
currentFiscalMonth = 6
actualMonth = 6
 
I solved the problem by tackling the code differently... Here is my NEW code
Code:
    Do While notHighlighted = 0
    
    If weekday = 1 Then  'similar code to the "first day of month is sunday, the below is varied slight based on weekday" but varied slightly to just find the first day of the month
        Sheets("Master Dial").Select
        Range("H4").Select
        Do While ActiveCell <> whatsToday
            ActiveCell.Offset(0, 1).Select
            If ActiveCell.Column = 9 Then
                ActiveCell.Offset(2, -7).Select
            End If
        If ActiveCell = whatsToday Then
            ActiveCell.Interior.ColorIndex = 6
            notHighlighted = 100
        End If
        
        Loop
        
    End If
    
    If weekday = 2 Then 'Monday
        Sheets("Master Dial").Select
        Range("B4").Select
        Do While ActiveCell <> whatsToday
            ActiveCell.Offset(0, 1).Select
            If ActiveCell.Column = 9 Then
                ActiveCell.Offset(2, -7).Select
            End If
        If ActiveCell = whatsToday Then
            ActiveCell.Interior.ColorIndex = 6
            notHighlighted = 100
        End If
        
        Loop
        
    End If
    
    If weekday = 3 Then 'Tuesday
        Sheets("Master Dial").Select
        Range("C4").Select
        Do While ActiveCell <> whatsToday
            ActiveCell.Offset(0, 1).Select
            If ActiveCell.Column = 9 Then
                ActiveCell.Offset(2, -7).Select
            End If
        If ActiveCell = whatsToday Then
            ActiveCell.Interior.ColorIndex = 6
            notHighlighted = 100
        End If
        
        Loop
        
    End If
    
    If weekday = 4 Then 'Wednesday
        Sheets("Master Dial").Select
        Range("D4").Select
        Do While ActiveCell <> whatsToday
            ActiveCell.Offset(0, 1).Select
            If ActiveCell.Column = 9 Then
                ActiveCell.Offset(2, -7).Select
            End If
        If ActiveCell = whatsToday Then
            ActiveCell.Interior.ColorIndex = 6
            notHighlighted = 100
        End If
        
        Loop
        
    End If
    
    If weekday = 5 Then 'Thursday
        Sheets("Master Dial").Select
        Range("E4").Select
        Do While ActiveCell <> whatsToday
            ActiveCell.Offset(0, 1).Select
            If ActiveCell.Column = 9 Then
                ActiveCell.Offset(2, -7).Select
            End If
        If ActiveCell = whatsToday Then
            ActiveCell.Interior.ColorIndex = 6
            notHighlighted = 100
        End If
        
        Loop
        
    End If
    
    If weekday = 6 Then 'Friday
        Sheets("Master Dial").Select
        Range("F4").Select
        Do While ActiveCell <> whatsToday
            ActiveCell.Offset(0, 1).Select
            If ActiveCell.Column = 9 Then
                ActiveCell.Offset(2, -7).Select
            End If
        If ActiveCell = whatsToday Then
            ActiveCell.Interior.ColorIndex = 6
            notHighlighted = 100
        End If
        
        Loop
        
    End If
    
    If weekday = 7 Then 'Saturday
        Sheets("Master Dial").Select
        Range("G4").Select
        Do While ActiveCell <> whatsToday
            ActiveCell.Offset(0, 1).Select
            If ActiveCell.Column = 9 Then
                ActiveCell.Offset(2, -7).Select
            End If
        If ActiveCell = whatsToday Then
            ActiveCell.Interior.ColorIndex = 6
            notHighlighted = 100
        End If
        
        Loop
        
    End If
    
    Loop
    
    
End If
The only issue is this way creates problems (endless loops on very specific dates, trying to fix them as I find them), id much rather tackle it the way we originally were trying to fix. If you do see where we went wrong with this (from above), please do let me know. No matter what though, I appreciated your help greatly!!!!! :)
 
Last edited:
Upvote 0
Hi,
I used Find method to search an Excel Calendar for a Day without any problem & should work ok for you.
Assuming this test "If actualMonth = currentFiscalMonth Then" is being met then try changing:

LookIn:=xlValues

to

LookIn:=xlFormulas

and see if that helps

Dave
 
Upvote 0
Thank you so much, that actually worked!!!! The code I used to try and get around it was pretty raw so im glad we could fix that, you are a saint!!! :) and seeing how you are from Hampshire, you may actually be a Southampton saint ;) as for me GGMU wish us luck today at 8!!!!
 
Upvote 0
Probably could have used conditional formatting but if code working now - glad got there in the end.

Good luck at 8.

Dave:)
 
Upvote 0

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