» 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
When you import numbers from data sources outside Excel it sometimes happens that the negative valuesis 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:
- The 11 Immutable Laws of Internet Branding
- Investments + S&P Card + Powerweb + StockTrak discount coupon
- Marketing Management
- The 22 Immutable Laws of Marketing : Exposed and Explained by the World's Two
- The South Beach Diet: The Delicious, Doctor-Designed, Foolproof Plan for Fast and Healthy Weight Loss
- Microsoft Excel 2002 Simply Visual
No comments have been submitted.

