# Need help with VBA "IF(AND)" function

#### joneil27

##### New Member
please i need help i am new to VBA
problems with "IF" & "AND"
the value of textbox1 = 0.7
the value of textbox2 = 0.8

i want to make textbox3 say a message
if textbox1 is greater than textbox 2 by 0.1 and lower than textbox2 by 0.1

textbox1 can not be lower or greater than textbox2 at the range of 0.1
meaning if textbox1 is 0.69 or 0.91 then textbox3 will say "not ok"

### Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

#### tygrrboi

##### Well-known Member
I think you mean OR... something cannot be both greater than AND less than a value.

Do you mean like this?

Code:
``````If ABS(VAL(Textbox1.Value) - VAL(Textbox2.Value)) > 0.1 Then
Textbox3.Value = "Not OK"
End If``````

#### joneil27

##### New Member
i used on worksheet =AND(H13>B8-0.1,H13<=D8+0.1)
but i cant make the same argument on vba

#### tygrrboi

##### Well-known Member
did you try what I suggested?

#### joneil27

##### New Member
Private Sub Label18_click()
Label18.ForeColor = RGB(255, 0, 0)
End Sub

Private Sub UserForm_Initialize()
AlwaysOnTop Me.caption
End Sub
Sub GetErr()
On Error GoTo 0
End Sub

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
UserForm1.Show
Application.ScreenUpdating = True
End Sub

Private Sub SpinButton1_Change()
TextBox3.Value = SpinButton1.Value
End Sub

Private Sub SpinButton2_Change()
TextBox15.Value = SpinButton2.Value
End Sub

Private Sub TextBox1_change()

ValidateNumber Me.TextBox1

End Sub

Private Sub TextBox17_Change()
End Sub

Private Sub TextBox2_Change()

ValidateNumber Me.TextBox2

End Sub

Private Sub TextBox3_Change()

ValidateNumber Me.TextBox3

End Sub

Private Sub TextBox15_Change()

ValidateNumber Me.TextBox15

End Sub
Private Sub TextBox5_Change()

ValidateNumber Me.TextBox5

End Sub
Private Sub TextBox6_Change()

ValidateNumber Me.TextBox6

End Sub
Private Sub TextBox7_Change()

ValidateNumber Me.TextBox7

End Sub
Private Sub TextBox8_Change()

ValidateNumber Me.TextBox8

End Sub
Private Sub TextBox9_Change()

ValidateNumber Me.TextBox9

End Sub
Private Sub TextBox10_Change()
ValidateNumber Me.TextBox10

End Sub
Private Sub TextBox11_Change()

ValidateNumber Me.TextBox11

End Sub
Private Sub TextBox12_Change()

ValidateNumber Me.TextBox12

End Sub
Private Sub TextBox13_Change()

ValidateNumber Me.TextBox13

End Sub
Private Sub TextBox14_Change()

ValidateNumber Me.TextBox14

End Sub

Sub ValidateNumber(textbox)

Dim sTxt As String

sTxt = textbox.Text
If sTxt = "" Then Exit Sub

If IsNumeric(sTxt) Then
If InStr(sTxt, ".") > 0 Then
If Len(sTxt) - InStr(sTxt, ".") > 2 Then
textbox.Text = Mid(sTxt, 1, Len(sTxt) - 1)
End If
End If

Exit Sub
End If
textbox.Text = Mid(sTxt, 1, Len(sTxt) - 1)

End Sub

With Me
sval1 = .TextBox1.Value
sVal2 = .TextBox2.Value
sval3 = .TextBox3.Value
sval15 = .TextBox15.Value
sval7 = .TextBox7.Value
sval8 = .TextBox8.Value
sval9 = .TextBox9.Value
sval10 = .TextBox10.Value
sval11 = .TextBox11.Value

If sval1 = "" Then sval1 = 100
If sVal2 = "" Then sVal2 = 100
If sval3 = "" Then sval3 = 100
If sval15 = "" Then sval15 = 100
If sval7 = "" Then sval7 = 100
If sval8 = "" Then sval8 = 100
If sval9 = "" Then sval9 = 100
If sval10 = "" Then sval10 = 100
If sval11 = "" Then sval11 = 100

dtotal = CDbl(sval1 * 2.1189)
.TextBox2 = Format(dtotal, "0")

dtotal = CDbl(sval3 / 25.4)
.TextBox5 = Format(dtotal, "0")

dtotal = CDbl(sval15 / 25.4)
.TextBox6 = Format(dtotal, "0")

dtotal = CDbl((1000 * sval1) / ((sval3 * sval15)))
.TextBox9 = Format(dtotal, "0.00")

dtotal = CDbl(sval9 * 196.8504)
.TextBox13 = Format(dtotal, "0")

dtotal = (sval7 / 25.4)
.TextBox11 = Format(dtotal, "0")

dtotal = CDbl(sval8 / 25.4)
.TextBox12 = Format(dtotal, "0")

dtotal = CDbl(((4 * (sval3 * sval15)) / ((2 * sval3) + (2 * sval15))))
.TextBox8 = Format(dtotal, "0")

dtotal = ((1.3 * (sval3 * sval15) ^ 0.625)) / Application.WorksheetFunction.Sum(sval3, sval15) ^ 0.25
.TextBox7 = Format(dtotal, "0.00")

dtotal = 6.05 * ((sval1 / 60) ^ 1.85) * 10 ^ 5 / 1.2 ^ 1.85 / (sval7 ^ 4.87) * 100000
.TextBox10 = Format(dtotal, "0.00")

dtotal = (sval10 * (0.004 / 3.28) * 100)
.TextBox14 = Format(dtotal, "0.00")

If dtotal = Application.WorksheetFunction.And(sval10 > (.TextBox18 + 0.1), sval10 < (.TextBox17 - 0.1)) Then
.TextBox16 = "Duct Size Accepted"
Else
.TextBox16 = "not ok"
End If
End With

End Sub

Sub Form_Current()
Dim curAmntDue As Currency, lngBlack As Long
Dim lngRed As Long, lngYellow As Long, lngWhite As Long

If Not IsNull(Me!txtPastDue.Value) Then
curAmntDue = Me!txtPastDue.Value
Else
Exit Sub
End If
lngRed = RGB(255, 0, 0)
lngBlack = RGB(0, 0, 0)
lngYellow = RGB(255, 255, 0)
lngWhite = RGB(255, 255, 255)
If curAmntDue > 100 Then
Me!txtPastDue.BorderColor = lngRed
Me!txtPastDue.ForeColor = lngRed
Me!txtPastDue.BackColor = lngYellow
Else
Me!txtPastDue.BorderColor = lngBlack
Me!txtPastDue.ForeColor = lngBlack
Me!txtPastDue.BackColor = lngWhite
End If
End Sub

Replies
0
Views
393
Replies
12
Views
598
Replies
6
Views
153
Replies
1
Views
1K
Replies
17
Views
1K

1,190,692
Messages
5,982,317
Members
439,773
Latest member
tyruschen

### 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.

### Which adblocker are you using?

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

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