View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz[_2_] JLGWhiz[_2_] is offline
external usenet poster
 
Posts: 1,565
Default Help with Selection.Replace

The button must be from the Control Toolbox to use the Click event. If the
button is from the Control Tool box, then put a break point on the first
line of the IF statement, then click the button to see if it breaks on that
line and highlights if for debugging. If it does not, then check the
spelling of the button name to be sure it is exactly like that shown in the
properties window.

If the code works when you run it manually, then the problem has to be in
either the type of button you are using or the name you are using in the
title line of the code.



"Ayo" wrote in message
...
When I run this click macro from inside a worksheet, nothing happens. The
changes I am trying to make are not done but the code works fine when I
run
it manually.
Any ideas what is going wrong?

Private Sub cmdMarketRegion_Click()
If Me.cmdMarketRegion.Caption = "Market" Then
Me.cmdMarketRegion.Caption = "Region"
Me.Range("D7,D23,D39") = "Market"
Me.Cells.Select
With Selection
.Replace What:="=$D$7", Replacement:="<"""
End With
Me.Range("A2").Select
ElseIf Me.cmdMarketRegion.Caption = "Region" Then
Me.cmdMarketRegion.Caption = "Market"
Me.Range("D7,D23,D39") = "Region"
Me.Cells.Select
With Selection
.Replace What:="--('InSite Milestones'!$A$2:$A$9245=$E$4)",
Replacement:="--('InSite
Milestones'!$A$2:$A$9245<"")"
End With
Me.Range("A2").Select
End If

Me.Calculate
End Sub