Ken,
I apologize but I'm having a very hard time understanding your 2 questions.
I think you're trying to put a strikethrough for your selected cells?
Select_Cells As Range ??? #1 ???
Should Be...
Dim Select_Cells as Range
then to make it know what cells you've already selected...
Set Select_Cells = Selection
mgCell.Font = mgCell.Font.Strikethrough
To make all selected cells have a Strikethrough it should be...
rngCell.Font.Strikethrough = True
MsgBox (mgCell) ! Just to see what is happening, will be removed
!
To show a message of what cell is being affected, should be...
MsgBox rngCell.Address
That said, here are some other thoughts.
In your example of 'When I strike through a number in a cell, I do not want
the number to sum in A5':
in cell A5 put...
=SumNotStrikeThru(A1:A2)
That will give you your correct answer by ignoring cells that have
strikethroughs.
If you format another cell with a strikethrough, just hit the F9 [Calculate]
key to ensure you have the correct total.
I suggest that you put the SumNotStrikeThru function in your Personal.xls so
that it will always be available to you.
'/===========================================/
Public Function SumNotStrikeThru(Select_Cells As Range) As Double
Dim rngCell As Range
Application.Volatile
On Error Resume Next
SumNotStrikeThru = 0
For Each rngCell In Select_Cells
If WorksheetFunction.IsNumber(rngCell) Then
If rngCell.Font.Strikethrough = False Then
SumNotStrikeThru = SumNotStrikeThru + rngCell.Value
End If
End If
Next rngCell
End Function
'/===========================================/
Note about User-Defined-Function SumNotStrikeThru():
Select_Cells is the range of cells to be analyzed. This selection of
cells can either be typed in or selected using the mouse. In the above
example, A1:A2 is the Select_Cells range.
rngCell is used in the FOR loop to look at each cell in the Select_Cells
range.
IsNumber - check to see if the cell being looked at (rngCell) is a number.
If it is then go to the next line of code, otherwise ignore it because we
only want to add numbers.
rngCell.Font.Strikethrough - check to see if the Strikethrough property of
the font of the cell being looked at (rngCell) has been turned on. If it has
been, ignore it, otherwise add it to the results you already have.
f you want to contact me directly, take the '_NOSPAM_' out of my email
address below.
HTH,
--
Gary Brown
gary_brown@ge_NOSPAM.com
If this post was helpful, please click the ''Yes'' button next to ''Was this
Post Helpfull to you?''.
Ken said:
One way to accomplish the tasks is to add a button to the spreadsheet that
will take the selected cells and:
Strikethrough the numbers in the cells
Then recalculate the worksheet.
My approach is shown below. The questions:
How do I bring the selected cells identifications into the button
subroutine? #1
Can I have the subroutine strike over the numbers in the cell? #2
Private Sub CommandButton2_Click()
Select_Cells As Range ??? #1 ???
Dim mgCell As Range
Application.Volatile
On Error Resume Next
For Each mgCell In Select_Cells
If WorksheetFunction.IsNumber(mgCell) Then
mgCell.Font = mgCell.Font.Strikethrough ??? #2 ???
MsgBox (mgCell) ! Just to see what is happening, will be removed !
End If
Next mgCell
Application.Calculate
End Sub
Can I do this?
Ken
best
bet ''Was
this to
sum in