Hello everyone,
I am working on a VBA code which changes positive figures to negative figures and vice versa.
The code works fine if i select more than 1 cells but if i select only one cell to change the figure from positive to negative or negative to positive then all other numbers get changed automatically in the sheet.
The code is as follows
Sub PlusMinus()
'Changes the sign on a selected range of numbers
Dim cell As Range
If Application.Count(Selection.Cells) = 0 Then
MsgBox "Non Numeric Data", vbOKOnly + vbExclamation, "Cannot Change Figures"
Exit Sub
End If
On Error Resume Next 'copies with cells that are not numeric
For Each cell In Selection.SpecialCells(xlCellTypeConstants, 23)
cell.Value = -cell.Value
Next cell
End Sub
I was also looking for a way to incorporate in the code which would ask for the range and then change the figures.
For example, if i need to change any number, i need to click the command button which would assigned with macro.
on clicking command button, a pop up message box should appear and ask for the range selection.
The figure should change from positive to negative or vice versa Once i select the range or a single cell and select OK button.
I hope i explained my query properly.
Thank you so much in advance.
Best Regards
I am working on a VBA code which changes positive figures to negative figures and vice versa.
The code works fine if i select more than 1 cells but if i select only one cell to change the figure from positive to negative or negative to positive then all other numbers get changed automatically in the sheet.
The code is as follows
Sub PlusMinus()
'Changes the sign on a selected range of numbers
Dim cell As Range
If Application.Count(Selection.Cells) = 0 Then
MsgBox "Non Numeric Data", vbOKOnly + vbExclamation, "Cannot Change Figures"
Exit Sub
End If
On Error Resume Next 'copies with cells that are not numeric
For Each cell In Selection.SpecialCells(xlCellTypeConstants, 23)
cell.Value = -cell.Value
Next cell
End Sub
I was also looking for a way to incorporate in the code which would ask for the range and then change the figures.
For example, if i need to change any number, i need to click the command button which would assigned with macro.
on clicking command button, a pop up message box should appear and ask for the range selection.
The figure should change from positive to negative or vice versa Once i select the range or a single cell and select OK button.
I hope i explained my query properly.
Thank you so much in advance.
Best Regards