Toggle Macro

M

Michael

I'm having trouble learning Macros. I need to toggle a single cell (d33) between a value of 8% and blank.

ALSO, I'd love a better site for help topic. MS really dropped the ball on this topic.

Thanks,
Michael
---
 
B

Bernie Deitrick

Michael,

Sub ToggleD33()
If Range("D33").Value = "" Then
Range("D33").Value = 0.08
Else
Range("D33").ClearContents
End If
End Sub

HTH,
Bernie
MS Excel MVP

Michael said:
I'm having trouble learning Macros. I need to toggle a single cell (d33)
between a value of 8% and blank.
 
T

Tom Ogilvy

Sub ToggleCell()
if isempty(Range("D33")) then
Range("D33").value = .08
Range("D33").Numberformat = "0%"
Else
Range("D33").ClearContents
End If
End Sub

--
Regards,
Tom Ogilvy


Michael said:
I'm having trouble learning Macros. I need to toggle a single cell (d33)
between a value of 8% and blank.
 
J

JulieD

Hi Michael

i would do it using:

Sub togglevalue()
If Sheets("Sheet1").Range("D33").Value = "" Then
Sheets("Sheet1").Range("D33").Value = 0.08
Else
Sheets("Sheet1").Range("D33").Value = ""
End If
End Sub

and format the cell to percentage
you can assign this code to a button / toolbar icon or shortcut key as you
wish

Hope this helps
Cheers
JulieD



Michael said:
I'm having trouble learning Macros. I need to toggle a single cell (d33)
between a value of 8% and blank.
 
B

Bob Phillips

Tom was the only one to give you the format as well, but the code

Range("D33").value = .08
Range("D33").Numberformat = "0%"

can be combined with

Range("D33").value = "8%"

Excel does the rest.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Michael said:
I'm having trouble learning Macros. I need to toggle a single cell (d33)
between a value of 8% and blank.
 
Top