Create strikethrough macro in Excel

I'm new to VBA, and I'm trying to make a simple macro where you can select a set of cells, click a button and cross out selected sales. After that, you can select the cell again, press the same button and delete the strikethrough.

I was looking for decent documentation, but haven't found anything yet.

Here is the code.

Also, I would be interested to know where the best VBA documentation is.

Sub strikeOut() Selection.Font.Strikethrough = True End Sub 

I also need help with a command button.

Thanks.

+4
source share
1 answer

You seem to be on the right track. Based on your code, I assume that you have already created a command button. If yes, try the following:

 Sub strikeOut() With Selection.Font .Strikethrough = Not .Strikethrough End With End Sub 

To create a command button:

  • Excel 2003 and earlier :
    • Open the Visual Basic toolbar and activate the Control Toolbox button. Another toolbar / toolbar should be displayed with various control options.
    • Select the Button option and place it in the right place.
  • Excel 2007 and later :
    • Click the Developer tab / ribbon.
    • Select Insert and select Button and place it in the right place.
  • * The following steps apply to all versions from now on.
    • Right-click on the new button and select Properties to give your button a name / signature.
  • Right-click again and select View Code .
  • On the ButtonName_Click() tab, add a strikeOut() call using:
    • Call strikeOut()
  • or simply
    • strikeOut

To answer the second part of your question, it's hard to say what is β€œbest,” but here are some links that might help:

Chip Pearson Website
MSDN
Ozgrid

+8
source

All Articles