Using If Then in VBA

Skip Bisconer

Active Member
Joined
Jun 14, 2002
Messages
263
I have nine lines that may or may not have numbers in them. When the user finishes entries the vba updates the lines entered into a printable form. I am using the following statement with the line numbers and txtnames changed for each available line.
' Update line one on quote form.
Sheet1.Select
With Selection
Range("A16") = txtQty1
Range("B16") = ComboBox1
Range("C16") = txtOrigin1
Range("G16") = txtDest1
Range("J16") = txtCost1
If txtQty1 <> "" Then
Range("K16") = txtQty1 * txtCost1
End If

This works great if txtQty1 is left blank however if txtCost1 is left blank the procedure errors out. Is there a way in an If Then statement to say If txtQty1 or txtCost1 is not blank then Range("K16") = txtQty1 * txtCost1?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Use

If txtQty1 <> "" And txtCost1 <> "" Then
'Do your calculation
....
End If

GNaga
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

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