Worksheet_Calculate on formula results in column

dougbert

Board Regular
Joined
Jul 12, 2007
Messages
91
Hi all,

I leveraged some code I found here in the forum. Very simple in appearance, but it always skips over my If statement if I step through the code even on dates that already exist.

Here's the setup. Workbook1 has about 600 cells with a Vlookup formula in column N. The Vlookup formula pulls its data from a column in Workbook2 which will return a date within a one year span in Workbook1 Column N once the column in Workbook2 is populated with a date within that same one year span. Inititially, the "date" column cells in Workbook2 are blank.

Once column N in Workbook1 displays a date, I want to change 3 cells in the same row as the newly appearing date to read "Y". I want the macro to automatically check for a date range within each cell in Workbook1 Column N and execute the 3 value changes in that same row as long as the date falls within the specified range.

Here's the leveraged code after I modiifed it to what I thought MIGHT work. I placed this code into the private module for worksheet in question in Workbook1. I used Excel date serial numbers in the code.

Code:
Private Sub Worksheet_Calculate()
For Each c In Range("N3:N600")
'If cell value is within date range 11/1/2010 to 10/31/2011 enter If statement to changes other column values.
    If c.Value >= "40483" And c.Value < "40848" Then
        c.Offset(0, -7).Value = "Y"
        c.Offset(0, -6).Value = "Y"
        c.Offset(0, -5).Value = "Y"
    End If
Next c
End Sub

I suspect the problem is that I'm not including code to monitor when the formulas finally display a value that is not "blank". Perhaps the "previously blank" values need to be stored in a temporary array for comparison to any new values that may exist each time the date is updated in Workbook2.

BTW: the code above works in a Worksheet_Change sub if I manually enter a date into Workbook1 Column N.

I'm open to ideas and suggestions.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try removing the quotes

Code:
If c.Value >= 40483 And c.Value < 40848 Then
 
Upvote 0
Duh! Thank you Peter! That was fast!!! :) ...and it worked!

Sometimes I can't see the forest for the trees!
 
Upvote 0

Forum statistics

Threads
1,215,039
Messages
6,122,802
Members
449,095
Latest member
m_smith_solihull

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