Validation VBA Code - Needs improvements

Trying2learnVBA

Board Regular
Joined
Aug 21, 2019
Messages
67
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello,

I am trying to compare if two different cells have the same value as in positive or negative. This is the code I have, but it keeps returning my desired output when both cells have the same sign (either both positive or both negative)

VBA Code:
Sub Validations()
''''''''''''''''''''''''''''''''''''''''''''''
'Formulas to fill out counterparty validations'
''''''''''''''''''''''''''''''''''''''''''''''
Dim WS1 As Worksheet
Set WS1 = ThisWorkbook.Sheets("CounterParty MTM Validations")

With WS1
'BoA
  .Range("B3").Value = .Range("A18")
  .Range("B4").Value = .Range("F18")
  .Range("B8").Value = .Range("A18")
  .Range("B9").Value = .Range("D18")
If .Range("B10") >= 100000 Or .Range("B10") <= -100000 Then
    .Range("A10").Value = "CALL"
Else
    .Range("A10").Value = "NO CALL"
End If

'this is not working, it always returns "Changing position"
If .Range("A8") > 0 And .Range("A9") > 0 Then
    .Range("A11").Value = "Changing Positions"
Else
    .Range("A11").Value = ""
End If

'I would like the same cell "A11 to have the output "Changing position" if my conditions are met, but I am ok having the output in separate cells
If .Range("A8") < 0 And .Range("A9") < 0 Then
    .Range("A12").Value = "Changing Positions"
Else
    .Range("A12").Value = ""
End If


End With
End Sub

Thank you for any pointers
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Any sample data when to meet or when to not meet condition?
 
Upvote 0
Any sample data when to meet or when to not meet condition?
Ok,

So, If say, A8 is a positive number.
and A9 is also a positive number.
Then the position is changing.

The position can also change if both are negative numbers.
Any number.

It might be A8 is 1000
A9 is -300
In this case, result should be nothing. ""

The other two cases would be say,
A8 is 100
A9 is 400
Both are positive. Position changes.
A8 is -200
A9 is -50
Both are negative. Position changes
 
Upvote 0
Try this
VBA Code:
Sub Validations()
''''''''''''''''''''''''''''''''''''''''''''''
'Formulas to fill out counterparty validations'
''''''''''''''''''''''''''''''''''''''''''''''
Dim WS1 As Worksheet
Set WS1 = ThisWorkbook.Sheets("CounterParty MTM Validations")

With WS1
'BoA
  .Range("B3").Value = .Range("A18")
  .Range("B4").Value = .Range("F18")
  .Range("B8").Value = .Range("A18")
  .Range("B9").Value = .Range("D18")
If .Range("B10") >= 100000 Or .Range("B10") <= -100000 Then
    .Range("A10").Value = "CALL"
Else
    .Range("A10").Value = "NO CALL"
End If

'this is not working, it always returns "Changing position"
If (.Range("A8") > 0 And .Range("A9") > 0) Or (.Range("A8") < 0 And .Range("A9") < 0) Then
    .Range("A11").Value = "Changing Positions"
Else
    .Range("A11").Value = ""
End If

End With
End Sub
 
Upvote 0
I did not see how you want to handle id number is zero, but sure you can handle that. :)
 
Upvote 0
I did not see how you want to handle id number is zero, but sure you can handle that. :)
Hey thank you!!

If both numbers are zero, no action is needed. This is for collateral calls based on margin. Daily mark to market fluctuations.
The "Changing positions" is simply a reminder for which direction the trade is going. Instead of memorizing every single little rule. I need to set up a few more but I need to understand the process better first. Thanks again
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,851
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top