Home |
Search |
Today's Posts |
#6
![]() |
|||
|
|||
![]()
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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel option to store trendline's coefficients in cells for use | Charts and Charting in Excel | |||
Date & Time | New Users to Excel | |||
Automatically up date time in a cell | Excel Discussion (Misc queries) | |||
clock | Excel Worksheet Functions | |||
How can I define Erf (the error function) for both negative and p. | Excel Discussion (Misc queries) |