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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

xld

Banned
Joined
Feb 8, 2003
Messages
5,378
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

Matt0110

New Member
Joined
Feb 21, 2008
Messages
45
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,191,717
Messages
5,988,257
Members
440,145
Latest member
arxoon

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