Vba Code alteration reqd.

Ian Betteridge

Active Member
Joined
Mar 25, 2006
Messages
472
Good Evening,
I have some code which was kindly supplied via this forum.

Private Sub Workbook_Open()
If Month(Date) > 1 Or Day(Date) >= 7 Then
With Sheets("wkssystemA2").Range("B64").Resize(1, Month(Date) - IIf(Day(Date) < 7, 1, 0))
.Value = .Value
End With
End If
End Sub

I now want this code to apply to all cells in the range CB3:CM59 and not cell B64.
Is this possible? If yes, what will the code become?
Regards Ian
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
How about:

With Sheets("wkssystemA2").Range("CB3:CM59").Resize(1, Month(Date) - IIf(Day(Date) < 7, 1, 0))
 
Upvote 0
Maybe like this

Code:
Private Sub Workbook_Open()
Dim c As Range
If Month(Date) > 1 Or Day(Date) >= 7 Then
    For Each c In Sheets("wkssystemA2").Range("CB31:CM59")
        With c.Resize(1, Month(Date) - IIf(Day(Date) < 7, 1, 0))
            .Value = .Value
        End With
    Next c
End If
End Sub
 
Upvote 0
I thought that was obvious, so I tried it before posting and it didn't work. That's where I got lost.
With regards to Bobs post.
 
Upvote 0
Hi Peter,
I've tried that and still can't get a result. I'd expect the cells CB3:CF59 to have changed from a formula to a number after closing down and then re-opening the workbook.
? Probably me but can't see where.
 
Upvote 0
This is probably not the problem, but this
For Each c In Sheets("wkssystemA2").Range("CB31:CM59")

probably only needs to be
For Each c In Sheets("wkssystemA2").Range("CB31:CB59")


Also, as Vog said this is all assuming the code you posted DOES actually work for the single cell.
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,911
Members
452,949
Latest member
beartooth91

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