View Single Post
 
Old 05-08-2015, 02:53 PM
dakm63 dakm63 is offline Windows 7 32bit Office 2007
Novice
 
Join Date: May 2015
Posts: 1
dakm63 is on a distinguished road
Default Excel VBA to convert number to negative

I want an entered number in a cell to be negative if there is any text in the previous cell in the row.
So if the user selects any value from the dropdown in A1, when they enter a numeric value in B1 it will convert to negative. I am able to accomplish this on a per cell basis using this code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range("A1:B1"), Target) Is Nothing Then
If IsNumeric(Range("B1").Value) Then
Application.EnableEvents = False
If Range("A1") = "" Then
Range("B1") = Abs(Range("B1").Value)
Else
Range("B1") = -Abs(Range("B1").Value)
End If
Application.EnableEvents = True
End If
End If
End Sub


But I am unable to figure out how to apply it to a range of cells from A1:A50 and B1:B50
Reply With Quote