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

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

gnaga

Well-known Member
Joined
Jul 9, 2002
Messages
700
Office Version
  1. 365
  2. 2016
  3. 2013
Platform
  1. Windows
Use

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

GNaga
 

Forum statistics

Threads
1,143,915
Messages
5,721,515
Members
422,369
Latest member
redinator

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
Top