I want to change a positive value cell input in a range to a negative value by reference to a criteria in another cell range. So for instance cell range A1:A10 contains either a value of "B" or "S". Cell range B1:B10 is where the numeric values are entered. These values when entered are either made positive or negative values depending on the data already entered in corresponding cells A1:A10. So entering any value whether positive or negative in say B1 as either 1234 or -1234 where A1 has a value "B" will result in B1 displaying -1234. Conversely where any value whether positive or negative is input in Cells B1:B10 and the value of the corresponding row in column A is "S" the value in column B will always be positive irrespective of whether the original input was negative or positive.
If there is no value in a particular cell in the range A1:A10 corresponding to the same row in column B then a message should be displayed to the user saying "Please enter a value in the corresponding row in column A.
I am a complete novice to VBA coding and so far looking at other posts have cobbled together following code, but I do not know how to complete it to work successfully.
Any help would be very much appreciated.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim A1 As Range
Set A1 = Range("A1:A10")
Dim A2 As Range
Set A2 = Range("B1:B10")
If Intersect(Target, A2) Is Nothing Then Exit Sub
If IsText(Target, A1) Then
If A1 = "S" Then
Application.EnableEvents = False
B1 = -B1
Application.EnableEvents = True
End If
End Sub
A1is an entire range of cells, so the comparisonA1 = "S"doesn't make sense. A 10-element range isn't a string. Look intoRange.Find()if you want to find if"S"is in the range. Alternatively, loop over the cells in that range, comparing each one in turn with"S". Also, yourIsTextdoesn't make sense. For one thing, that is a worksheet function, not a VBA function. For another thing, it takes one argument, not two. - John Coleman