Make this into a toggle command? [XL2003]

S

StargateFan

I have a simple script that works only okay when going in one
direction, putting a strikethrough when on a particular line:

With Selection.Font
.Strikethrough = True
End With

I needed to be able to have a script firstly, behave in a toggle
fashion - i.e., press the button and the strikethrough is applied,
press the button and it's taken off.

Then it would be good to have this work on any given line one is on
that it puts the strikethrough on that line for the 2 columns in that
spreadsheet for that line, columns A and B.

What code would do this pls? I have only one spreadsheet that applies
a border line with various "attributes", I think they'd be called
(certain line style, colour, etc.) but it applies to a top border and
no amount of working with the code has yielded what I need. I seem to
still be a junior at all this even after all this time! <sheepish
grin>

Thank you!
 
D

Don Guillett Excel MVP

I have a simple script that works only okay when going in one
direction, putting a strikethrough when on a particular line:

    With Selection.Font
        .Strikethrough = True
    End With

I needed to be able to have a script firstly, behave in a toggle
fashion - i.e., press the button and the strikethrough is applied,
press the button and it's taken off.

Then it would be good to have this work on any given line one is on
that it puts the strikethrough on that line for the 2 columns in that
spreadsheet for that line, columns A and B.

What code would do this pls?  I have only one spreadsheet that applies
a border line with various "attributes", I think they'd be called
(certain line style, colour, etc.) but it applies to a top border and
no amount of working with the code has yielded what I need.  I seem to
still be a junior at all this even after all this time!  <sheepish
grin>

Thank you!

Sub togglestrikethru() 'selected cell(s)
Selection.Font.Strikethrough = _
Not Selection.Font.Strikethrough
End Sub

Sub togglestrikethruCOLS() 'columns a:b
mr = ActiveCell.Row
Cells(mr, 1).Resize(, 2).Font.Strikethrough = _
Not Cells(mr, 1).Resize(, 2).Font.Strikethrough
End Sub
 
J

Jim Cone

Does one row, two columns - starting from the top left selected cell...
With Selection.Resize(1, 2).Font
.Strikethrough = Not .Strikethrough
End With
--
Jim Cone
Portland, Oregon USA
http://www.mediafire.com/PrimitiveSoftware

..
..
..

"StargateFan" <[email protected]>
wrote in message
I have a simple script that works only okay when going in one
direction, putting a strikethrough when on a particular line:

With Selection.Font
.Strikethrough = True
End With

I needed to be able to have a script firstly, behave in a toggle
fashion - i.e., press the button and the strikethrough is applied,
press the button and it's taken off.

Then it would be good to have this work on any given line one is on
that it puts the strikethrough on that line for the 2 columns in that
spreadsheet for that line, columns A and B.

What code would do this pls? I have only one spreadsheet that applies
a border line with various "attributes", I think they'd be called
(certain line style, colour, etc.) but it applies to a top border and
no amount of working with the code has yielded what I need. I seem to
still be a junior at all this even after all this time! <sheepish
grin>

Thank you!
 
J

Jim Cone

Harald,
Glad you are still hanging around.
Thanks.
'--
Jim Cone


"Harald Staff" <[email protected]>
wrote in message
Those will err with mixed content. I suggest reading one cell only:

Sub A() 'selected cell(s)
Selection.Font.Strikethrough = _
Not Selection(1).Font.Strikethrough
End Sub

Sub B()
Selection.Resize(1, 2).Font.Strikethrough = _
Not Selection(1).Font.Strikethrough
End Sub

Best wishes Harald
 
S

StargateFan

I'm so very, very sorry, but on trying out all these suggestions -
they all work lovely, thank you - I realized that I shouldn't make
this toggable. Of course, when I tested it, I mis-clicked and saw how
too easy it was to reset something that shouldn't be reset. Glad I
figured this out now rather than later <g>, though. This sheet is to
keep track of items that need to get done so we must be absolutely
sure that only accomplished items get the strikethrough. So the
button should turn the strikethrough on only, after all. And a
separate script with value to false can be accessed by the user
manually so that taking the strikethrough off is done on purpose and
never by mistake.

Phew. Good to figure that out.

So I thought it would be easy to figure out how to get the vb code to
apply the strikethrough to columns A and B on the which one is on but,
blunderwoman strikes again, I can't figure it out. I've spent the
last 40 minutes on the archives of this ng and nothing.

The only spreadsheet I have that applies formatting to a row in a
similar manner deals with the borders so I don't know how to change it
to deal with the font and text within a cell.

So the simple code seems to still be good:

With Selection.Font
.Strikethrough = True
End With

Just need to change the above so that strikethrough is applied to
columns A and B of the active row.

Thanks so much! :blush:D
 
J

Jim Cone

Sub DoneAlready()
Dim Rw As Long
Rw = ActiveCell.Row
Range(Cells(Rw, 1), Cells(Rw, 2)).Font.Strikethrough = True
End Sub
 
S

StargateFan

Sub DoneAlready()
Dim Rw As Long
Rw = ActiveCell.Row
Range(Cells(Rw, 1), Cells(Rw, 2)).Font.Strikethrough = True
End Sub

This works great, thanks!

Well, you guys never need worry that I'll be so good I'll be able to
join your team!! <lol>

I tried seeing if I could reuse this for other row functions but I get
an error so thought I'd run it by you all to see what in heck I'm
doing wrong this time.

Dim Rw As Long
Rw = ActiveCell.Row
Range(Cells(Rw, 1), Cells(Rw, 2)).Font
.Strikethrough = True
.Bold = True
' .Color = RGB(0, 0, 0) ' change colour to black

If I need to change any other attributes, how can I change the above
to accommodate any other font changes needed?

Thanks much!!! :blush:D
 
G

Gord Dibben

Dim Rw As Long
Rw = ActiveCell.Row
With Range(Cells(Rw, 1), Cells(Rw, 2)).Font
.Strikethrough = True
.Bold = True
.Color = RGB(0, 0, 0) ' change colour to black
End With


Gord Dibben MS Excel MVP
 
S

StargateFan

Dim Rw As Long
Rw = ActiveCell.Row
With Range(Cells(Rw, 1), Cells(Rw, 2)).Font
.Strikethrough = True
.Bold = True
.Color = RGB(0, 0, 0) ' change colour to black
End With

Gord Dibben MS Excel MVP

Marvellous! Thank you. I added the colour option back in after all
and searched for RGB values. I added red to one and black to the
other. Works great. Now I also can't accidentally toggle something
OFF when it shouldn't be. I might toggle it ON by mistkae but then
can manually take strikethrough off if I realized I slip-clicked.
Best of both worlds - I have speed in striking through yet can back
out if I pressed the button in error.

Cheers!

:blush:D
 
S

StargateFan

After a few days working with this file, I "finetuned" the macros so
that they give me the results I need. I'm very sure there's a better
way to do these things but these do the job. The first is tied to a
button, the second users have to access via the macros menus.

----------------------------------------------------------------------
Sub DONE_Crosses_off_line() ' Columns A:B

ActiveSheet.Unprotect 'place at the beginning of the code

Dim Rw As Long
Rw = ActiveCell.Row
' With Range(Cells(Rw, 1), Cells(Rw, 2)).Font ' Cells(Rw,1) =
start cell ; Cells(Rw,2) = end cell
With Range(Cells(Rw, 1), Cells(Rw, 2)).Font
.Strikethrough = True
End With
With Range(Cells(Rw, 1), Cells(Rw, 3)).Font
.Color = RGB(255, 0, 0) ' change colour to RED
.Bold = True
End With

ActiveSheet.Protect ' place at end of code
End Sub
----------------------------------------------------------------------
Sub a_Strikethrough_Remove() ' Columns A:B
ActiveSheet.Unprotect 'place at the beginning of the code

Dim Rw As Long
Rw = ActiveCell.Row
' With Range(Cells(Rw, 1), Cells(Rw, 2)).Font ' Cells(Rw,1) =
start cell ; Cells(Rw,2) = end cell
With Range(Cells(Rw, 1), Cells(Rw, 2)).Font
.Strikethrough = False
End With
With Range(Cells(Rw, 1), Cells(Rw, 3)).Font
.Color = RGB(0, 0, 0) ' change colour back to BLACK
.Bold = False
End With

ActiveSheet.Protect ' place at end of code
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top