Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 276
Default Is there a Glitch in this code or what ? Not consistant results !!!

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Is there a Glitch in this code or what ? Not consistant results !!!

Try

With Range("E2")
.Value = .Value - 7
End With

Regards

Trevor


"Corey" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Is there a Glitch in this code or what ? Not consistant results !!!

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

"Corey" wrote in message
...
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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding consistant cells. dpal Excel Discussion (Misc queries) 4 March 25th 09 02:41 AM
merged cells - code glitch Horatio J. Bilge, Jr. Excel Discussion (Misc queries) 9 October 10th 07 09:27 PM
Macro not consistant Don Guillett Excel Discussion (Misc queries) 4 November 21st 06 10:44 PM
Macro not consistant grok Excel Discussion (Misc queries) 6 November 21st 06 09:27 PM
Code Glitch from version to version Shawn Excel Programming 2 November 24th 04 02:45 AM


All times are GMT +1. The time now is 05:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"