Multiply numbers in workbook by (-1)

  • Thread starter Thread starter agkistras
  • Start date Start date
A

agkistras

I want to multiply every number of every sheet in a workbook by (-1).
How can I do that using vba? Each sheet contains cells with numbers and
cells with formulas that sum up the number of other cells. I only want to
change the numbers.

Any ideas? Thanks.
 
Hi,

Right click any sheet tab, view code and paste this in and run it.

Sub stantial()
For x = 1 To Worksheets.Count
On Error Resume Next
Worksheets(x).UsedRange.SpecialCells(xlCellTypeConstants,
xlNumbers).Select
For Each c In Selection
c.Value = c.Value * -1
Next
Next
End Sub

Mike
 
Sub test()

For Each sht In ThisWorkbook.Sheets
On Error Resume Next
Set ConstCells = sht.Cells.SpecialCells( _
Type:=xlCellTypeConstants, _
Value:=xlNumbers)
On Error GoTo 0
For Each cell In ConstCells
cell.Value = cell.Value * 1
Next cell
Next sht


End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top