Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 30
Default Combine 2 VBA Replacements

I have the following code to replace two values in my sheet:

Public Sub Replace_Y_With_Rate5()
For Each cell In Selection
cell.Value = Replace(cell.Value, "Y", "24", 1, 1, vbTextCompare)
cell.Value = Replace(cell.Value, "CP", "8", 1, 1, vbTextCompare)
Next cell
End Sub

I'm wondering if I could combine these actions into one calculation (and how
to do so); reason being I have another macro that is executed after each
worksheet calculation to display a pop-up message. If the above macro is
executed I receive two pop-ups (because of the separate lines = separate
calculations, I believe) and want only one (pop-up to be displayed).

Thanks,

CVinje
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Combine 2 VBA Replacements

You could stop the call to the worksheet_change/worksheet_calculate event:

Public Sub Replace_Y_With_Rate5()
application.enableevents = false
For Each cell In Selection
cell.Value = Replace(cell.Value, "Y", "24", 1, 1, vbTextCompare)
cell.Value = Replace(cell.Value, "CP", "8", 1, 1, vbTextCompare)
Next cell
application.enableevents = true
End Sub

or even just plop the new value back just once:

Public Sub Replace_Y_With_Rate5()
dim myVal as variant

For Each cell In Selection
myval = cell.value
myval = Replace(myval, "Y", "24", 1, 1, vbTextCompare)
myval = Replace(myval, "CP", "8", 1, 1, vbTextCompare)
'and check
if myval < cell.value then
application.enableevents = false
cell.value = myval
application.enableevents = true
end if
Next cell

End Sub

CVinje wrote:

I have the following code to replace two values in my sheet:

Public Sub Replace_Y_With_Rate5()
For Each cell In Selection
cell.Value = Replace(cell.Value, "Y", "24", 1, 1, vbTextCompare)
cell.Value = Replace(cell.Value, "CP", "8", 1, 1, vbTextCompare)
Next cell
End Sub

I'm wondering if I could combine these actions into one calculation (and how
to do so); reason being I have another macro that is executed after each
worksheet calculation to display a pop-up message. If the above macro is
executed I receive two pop-ups (because of the separate lines = separate
calculations, I believe) and want only one (pop-up to be displayed).

Thanks,

CVinje


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,646
Default Combine 2 VBA Replacements

cell.Value = Replace(Replace(cell.Value, "Y", "24", 1, 1, vbTextCompare), _
"CP", "8", 1, 1, vbTextCompare)
Regards,
Stefi

€žCVinje€ť ezt Ă*rta:

I have the following code to replace two values in my sheet:

Public Sub Replace_Y_With_Rate5()
For Each cell In Selection
cell.Value = Replace(cell.Value, "Y", "24", 1, 1, vbTextCompare)
cell.Value = Replace(cell.Value, "CP", "8", 1, 1, vbTextCompare)
Next cell
End Sub

I'm wondering if I could combine these actions into one calculation (and how
to do so); reason being I have another macro that is executed after each
worksheet calculation to display a pop-up message. If the above macro is
executed I receive two pop-ups (because of the separate lines = separate
calculations, I believe) and want only one (pop-up to be displayed).

Thanks,

CVinje

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
How do I combine worksheets w/o enough rows to combine? Amanda W. Excel Worksheet Functions 3 June 9th 09 07:26 AM
Combine cells with the same reference and combine quantities brandon Excel Discussion (Misc queries) 2 September 17th 08 05:44 PM
combine or if littlelouise1 Excel Worksheet Functions 4 July 7th 08 09:26 PM
Combine into one please. Steved Excel Worksheet Functions 2 February 22nd 05 11:46 PM
Stop excel from reporting replacements Chris Excel Discussion (Misc queries) 1 January 7th 05 01:37 AM


All times are GMT +1. The time now is 07:44 PM.

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

About Us

"It's about Microsoft Excel"