» Convert negative values treated as text using VBA in Microsoft Excel
VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
CATEGORY - General Topics in VBA
VERSION - All Microsoft Excel Versions
is treated as text if they have the minus sign after the value.
With the macro below you can convert these negative numbers to a valid negative value Excel can perform calculations with:
Sub ConvertNegNumbers()
Dim cl As Range, a As Integer
If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
Application.ScreenUpdating = False
Application.StatusBar = "Converting negative values..."
a = Selection.Areas.Count
If a = 1 And Selection.Cells.Count = 1 Then ActiveSheet.UsedRange.Select
For a = 1 To Selection.Areas.Count
For Each cl In Selection.Areas(a).Cells
If Right(cl.Formula, 1) = "-" Then
cl.Formula = "-" & Left(cl.Formula, Len(cl.Formula) - 1)
End If
Next cl
Next a
Application.StatusBar = False
Application.ScreenUpdating = True
End Sub
Book Store:
Recommended Books:
- Microsoft Excel Version 2002 Step by Step
- Successful Business Planning in 30 Days: A Step-By-Step Guide for Writing a Business Plan and Starting Your Own Business
- H&R Block's Just Plain Smart(tm) Tax Planning Advisor: A year-round approach to lowering your taxes this year, next year and beyond
- The Analysis and Use of Financial Statements
- Treason: Liberal Treachery from the Cold War to the War on Terrorism
- Financial Statement Analysis with S&P insert card
No comments have been submitted.

