Is there a Glitch in this code or what ? Not consistant results !!!

C

Corey

Is there a Glitch with this Code?

I have 2 identical codes as below, except for what is highlighted below.


Sub callUnDoUpdates()
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In Application.Worksheets
ws.Select
With Range("E2")
..Value = Range("E2").Value - 7 '<====== Other code has an ADD instead of
a Subtract ".Value = Range("E2").Value + 7"
Application.ScreenUpdating = False
End With
Next
Sheet4.Select
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub


It works when the macro is run sometimes(subtracting 7days from the E2
date),
yet other times it jumps from 31 October 2006 to 11 July 2006.

Regards

Corey
 
N

NickHK

Corey,
I would guess it a question of exactly which cell/sheet is having the +/-7
from its value.
It would help to be more clear:

Dim WS As Worksheet
'Which workbook is this ?
'For Each ws In Application.Worksheets

'Make it clear, whichever WB it is
For Each WS In ThisWorkbook.Worksheets
'ws.Select No need
With WS.Range("E2")
.Value = .Value - 7
End With
Next

If that is what you intend ?

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top