Object Variable or with block variable not set

natnat

New Member
Joined
Sep 3, 2015
Messages
2
Hey all! Beginner here :) I get the "Object variable or with block variable not set" not sure why? I'd like the code to input specific values in cells based on months entered in in table header cells. Therefore the code should search for specific month names in each cell within the range MyRange, and enter figures in the cells beneath each months. Here is the code that I have. it shows me the error message after running and entering all the info I need. What is the error please? thanks

Code:
Dim PMonthRows As Range
Dim Cell As Object
Dim Aug13Range As Range
Dim Sep13Range As Range
Dim Oct13Range As Range

For Each Cell In PMonthRows
    If Cell.Value = #8/1/2013# Then
    If Aug13Range Is Nothing Then
    
    Set Aug13Range = Range(Cell.Address)
    End If
    End If
 
 Next
    
    Aug13Range.Select
    Aug13Range.Offset(1, 0).Value = 0
    Aug13Range.Offset(2, 0).Value = 4
    
 For Each Cell In PMonthRows
    If Cell.Value = #9/1/2013# Then
    If Sep13Range Is Nothing Then
    
    Set Sep13Range = Range(Cell.Address)
    End If
    End If
    
 Next
    
    Sep13Range.Select
    Sep13Range.Offset(1, 0).Value = 0
    Sep13Range.Offset(2, 0).Value = 4
    
For Each Cell In PMonthRows
    If Cell.Value = #10/1/2013# Then
    If Oct13Range Is Nothing Then
    
    Set Oct13Range = Range(Cell.Address)
    End If
    End If
    
 Next
    
    Oct13Range.Select
    Oct13Range.Offset(1, 0).Value = 8
    Oct13Range.Offset(2, 0).Value = 5

And so on...

I checked and all my variable are set, what have I done wrong? Thanks very much for your help :)
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Where do you get the error?

Also, where do you set PMonthRows?
 
Upvote 0

Forum statistics

Threads
1,215,268
Messages
6,123,966
Members
449,137
Latest member
yeti1016

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