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.
Any help would be apprieciated
Regards
pwill
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