Better coding for 3 If arguements

Matt0110

New Member
Joined
Feb 21, 2008
Messages
45
Hi all,

I was hoping someone could show me how to compress the 3 'ifs' below into a better arguement. At the moment it is possible to get the message box appearing 3 times when i only want it to appear once if one of the conditions are met.

If TextBox10.Value = "0" Then
MsgBox "The first line of data will be in red as this no consumption figures can be realised from the first reading!"
ActiveSheet.Range("q" & Rows.Count).End(xlUp) = TextBox9.Value
End If

If TextBox12.Value = "0" Then
MsgBox "The first line of data will be in red as this no consumption figures can be realised from the first reading!"
ActiveSheet.Range("s" & Rows.Count).End(xlUp) = TextBox11.Value
End If

If TextBox14.Value = "0" Then
MsgBox "The first line of data will be in red as this no consumption figures can be realised from the first reading!"
ActiveSheet.Range("u" & Rows.Count).End(xlUp) = TextBox13.Value
End If

Any hlep would be appreciated!

Thanks in advance,

Matt
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Code:
If TextBox10.Value = "0" Then
MsgBox "The first line of data will be in red as this no consumption figures can be realised from the first reading!"
ActiveSheet.Range("q" & Rows.Count).End(xlUp) = TextBox9.Value

ElseIf TextBox12.Value = "0" Then
MsgBox "The first line of data will be in red as this no consumption figures can be realised from the first reading!"
ActiveSheet.Range("s" & Rows.Count).End(xlUp) = TextBox11.Value

ElseIf TextBox14.Value = "0" Then
MsgBox "The first line of data will be in red as this no consumption figures can be realised from the first reading!"
ActiveSheet.Range("u" & Rows.Count).End(xlUp) = TextBox13.Value
End If
 
Upvote 0
Hi all,

I've replaced my code with the code below and it achieves what i want.

Cheers,

Code:
If TextBox12.Value = "0" Or TextBox10.Value = "0" Or TextBox14.Value = "0" Then
MsgBox "The first line of data will be in red as there are no consumption figures that can be realised from the first reading!"
ActiveSheet.Range("s" & Rows.Count).End(xlUp) = TextBox11.Value
End If
[/quote]
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,614
Members
449,090
Latest member
vivek chauhan

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