Duke Carey wrote...
....
DOUBLE NOTE: One of the MVPs here could probably streamline
this code quite a bit
MVPs aren't the only one who could streamline this (and remove
bugs).
Sub MakeValuesNegative()
Dim rngTgt As Range
Dim rngNegOne As Range
Dim intRows As Long
Application.ScreenUpdating = False
Set rngTgt = Selection
With ActiveSheet.UsedRange
intRows = .Rows.Count
Set rngNegOne = .Offset(intRows, 0).Resize(1, 1)
End With
You're making the unfounded assumption that UserRange always
begins in row 1. Open a new workbook and enter XYZ in cell
F10. Call up the
VB Editor and check what that worksheet's
UsedRange is.
rngNegOne = -1
rngNegOne.Copy
rngTgt.PasteSpecial xlPasteValues, xlPasteSpecialOperationMultiply
rngNegOne.Clear
End Sub
Why screw around with the entire selection if you're only
going to change a single cell. Why not change only the
ActiveCell? Why screw around with Copy and PasteSpecial?
Sub foo()
'overengineered
Dim c As Range, r As Range, s As Boolean
On Error GoTo CleanUp
s = Application.EnableEvents
Application.EnableEvents = False
Set r = Selection.SpecialCells( _
Type:=xlCellTypeConstants, Value:=xlNumbers)
For Each c In r.Cells
c.Value = -c.Value
Next c
CleanUp:
Application.EnableEvents = s
End Sub