If Cell Value Greater Than -1 Exit Sub

pwill

Active Member
Joined
Nov 22, 2015
Messages
406
Hi can anyone help with vba code?

I have a Sub named 'My Data'

I have values in cells D3 and D4 Sheet2 and want to call a Sub named 'DataValues' then exit sub but only when D3 = D4 greater than -1

eg

(A) - if D3 value is 1 and D4 value is 3 then I want Sub 'My Data' to call Sub 'DataValues' then exit Sub.

but

(B) - if D3 value is 1 and D4 value is 2 then I just want to end the IF statement and continue with the Sub 'My Data'

(C)- if D3 value is 7 and D4 value is 5 then I just want to end the IF statement and continue with the Sub 'My Data'

The code I have works with the line highlighted in red when (A) is true but still calls Sub 'DataValues' when (B) and (C) is true.

Code:
Sub MyData()


    Dim FromSht As Worksheet: Set FromSht = Sheet1
    Dim ToSht As Worksheet: Set ToSht = Sheet2
    Dim lRowW As Long

    
    lRowW = FromSht.Cells(Rows.Count, "W").End(xlUp).Row
        
        With ToSht
                If Range("D4") = "" Then
                    GoTo Continue
                End If
            [COLOR=#ff0000]If Range("D3") = Range("D4") > -1 Then[/COLOR]
                [COLOR=#ff0000]Call DataValues[/COLOR]
                Exit Sub
            End If
        End With
    
Continue:
        If lRowW = 2 Then
            FromSht.Range("W2").ClearContents
                    Range("D4").ClearContents
                    Exit Sub
                Else:
                    If lRowW = 1 Then
                    Range("D3").ClearContents
                Exit Sub
            End If
        End If
End Sub


Any help would be apprieciated

Regards

pwill
 
Hi Fluff, thank you so much, that works now :)

much appreciated, I spent all day trying to figure that out lol

regards

pwill
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Glad we could help & thanks for the feedback
 
Upvote 0
YOUR POST #1
I have a Sub named 'My Data'


I have values in cells D3 and D4 Sheet2 and want to call a Sub named 'DataValues' then exit sub but only when D3 = D4 greater than -1

eg

(A) - if D3 value is 1 and D4 value is 3 then I want Sub 'My Data' to call Sub 'DataValues' then exit Sub.

D3 is not equal to D4 so why are you calling sub datavalues
 
Upvote 0
Hi, Sorry only just seen this post, I am calling Sub DataValues when the difference between D3 & D4 is greater than 1 because the values in these cells change frequently,
I have it set now to how Fluff has it with

D4-1 > D3

it seems to work fine as and when the values change

Regards

pwill

YOUR POST #1
I have a Sub named 'My Data'


I have values in cells D3 and D4 Sheet2 and want to call a Sub named 'DataValues' then exit sub but only when D3 = D4 greater than -1

eg

(A) - if D3 value is 1 and D4 value is 3 then I want Sub 'My Data' to call Sub 'DataValues' then exit Sub.

D3 is not equal to D4 so why are you calling sub datavalues
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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