Private Sub Worksheet_Activate()

royca

New Member
Joined
Jan 27, 2011
Messages
44
I am using the following code on a few different sheets for input from an audit. I don't know if it is the best way to collect input but I like it. What I would like to do is reset the column with the wingdings font "o" every time the user changes sheets. I can not quite seem to figure out the right syntax. How do I make Range("C2:C20") all "o" every time I select the sheet?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("C2:C20")) Is Nothing Then
Cancel = True
With Target
.Font.Name = "Wingdings"
.Font.Size = 20
.HorizontalAlignment = xlCenter
End With
If Target.Value = "o" Then
Target.Value = "þ"
Target.Font.ColorIndex = 10
ElseIf Target.Value = "þ" Then
Target.Value = "ý"
Target.Font.ColorIndex = 3
ElseIf Target.Value = "ý" Then
Target.Value = "o"
Target.Font.ColorIndex = 0
Else
Target.Value = "þ"
Target.Font.ColorIndex = 10
End If
End If
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
put in the workbook module
Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Set Target = Range("C2:C20")
Cancel = True
With Target
  .Font.Name = "Wingdings"
  .Font.Size = 20
  .HorizontalAlignment = xlCenter
End With
For Each cell In Target
  With cell
    If .Value = "o" Then
      .Value = "þ"
      .Font.ColorIndex = 10
    ElseIf .Value = "þ" Then
      .Value = "ý"
      .Font.ColorIndex = 3
    ElseIf .Value = "ý" Then
      .Value = "o"
      .Font.ColorIndex = 0
    Else
      .Value = "þ"
      .Font.ColorIndex = 10
    End If
  End With
Next
End Sub
 
Upvote 0
Code:
Private Sub Worksheet_Activate()
Range("C2:C20") = "o"
end sub
or perhaps:
Code:
Private Sub Worksheet_Activate()
With Range("C2:C20")
  .Value = "o"
  .Font.ColorIndex = 0
End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,725
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top