Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default For each next

I have a macro that cycles through each cell in a range, eg

for each CELL in RANGE

This seems to work OK until I include something in the code that changes the
value of CELL, and then the macro just ends at that point.

I have tried declaring CELL as a range but no success.

Any clues as to why this might happen?

Regards, Kaval






  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default For each next

Hi Kaval,

Sub TestIt2()
Dim rCell As Range
Dim rng As Range

Set rng = Range("A1:A10")

For Each rCell In rng
With rCell
If IsNumeric(.Value) Then
.Value = .Value * 2
End If
End With
Next rCell

End Sub


---
Regards,
Norman



"Kaval" wrote in message
...
I have a macro that cycles through each cell in a range, eg

for each CELL in RANGE

This seems to work OK until I include something in the code that changes
the
value of CELL, and then the macro just ends at that point.

I have tried declaring CELL as a range but no success.

Any clues as to why this might happen?

Regards, Kaval








  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default For each next

Thanks, I since discovered I had a worksheet change event that was running
when I changed the cells and this was ending the code execution.

Thanks.

"Norman Jones" wrote:

Hi Kaval,

Sub TestIt2()
Dim rCell As Range
Dim rng As Range

Set rng = Range("A1:A10")

For Each rCell In rng
With rCell
If IsNumeric(.Value) Then
.Value = .Value * 2
End If
End With
Next rCell

End Sub


---
Regards,
Norman



"Kaval" wrote in message
...
I have a macro that cycles through each cell in a range, eg

for each CELL in RANGE

This seems to work OK until I include something in the code that changes
the
value of CELL, and then the macro just ends at that point.

I have tried declaring CELL as a range but no success.

Any clues as to why this might happen?

Regards, Kaval









  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default For each next

Thanks, I since discovered I had a worksheet change event that was running

Would this idea help?

Sub Demo()
Dim Cell As Range

'// Don't be interrupted by "Worksheet_Change"
Application.EnableEvents = False
For Each Cell In [A1:C4]
Cell = Rnd
Next
Application.EnableEvents = True
End Sub


--
Dana DeLouis
Win XP & Office 2003


"Kaval" wrote in message
...
Thanks, I since discovered I had a worksheet change event that was running
when I changed the cells and this was ending the code execution.

Thanks.

"Norman Jones" wrote:

Hi Kaval,

Sub TestIt2()
Dim rCell As Range
Dim rng As Range

Set rng = Range("A1:A10")

For Each rCell In rng
With rCell
If IsNumeric(.Value) Then
.Value = .Value * 2
End If
End With
Next rCell

End Sub


---
Regards,
Norman



"Kaval" wrote in message
...
I have a macro that cycles through each cell in a range, eg

for each CELL in RANGE

This seems to work OK until I include something in the code that
changes
the
value of CELL, and then the macro just ends at that point.

I have tried declaring CELL as a range but no success.

Any clues as to why this might happen?

Regards, Kaval











  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default For each next

Hi Kaval,

Post your problematic code, if necessary.


---
Regards,
Norman



"Kaval" wrote in message
...
I have a macro that cycles through each cell in a range, eg

for each CELL in RANGE

This seems to work OK until I include something in the code that changes
the
value of CELL, and then the macro just ends at that point.

I have tried declaring CELL as a range but no success.

Any clues as to why this might happen?

Regards, Kaval










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



All times are GMT +1. The time now is 04:20 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"