Run macro only if 2 criteria apply

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,651
Office Version
  1. 2007
Platform
  1. Windows
Hi,

I am currently using the following code supplied.
It works fine as it should but i have noticed that if the cell B13 has no value the macro still runs.
Please can you advise an edit to add to the supplied code so not only must cell B13 be active BUT it must also contain a value


Code:
Sub HondaEpcNumber_Click()    If ActiveCell.Address(0, 0) = "B13" Then
        HondaParts.MyPartNumber.Value = ActiveCell.Value
        HondaParts.Show
    Else
        MsgBox "You didn`t enter a Honda Part Number In Cell B13", vbExclamation, "Honda Number - My Number Look Up"
    End If
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
If ActiveCell.Address(0, 0) = "B13" And Cells(13, "B") <> Null Then
If ActiveCell.Address(0, 0) = "B13" And Cells(13, "B") <> "" Then



I am not 100% which is better, Null is when it has never been used. "" could be deleted value.

Or even better
Code:
Sub HondaEpcNumber_Click()


If Cells(13, "B") <> "" Then
        HondaParts.MyPartNumber.Value = Cells(13, "B")
        HondaParts.Show
    Else
        MsgBox "You didn`t enter a Honda Part Number In Cell B13", vbExclamation, "Honda Number - My Number Look Up"
    End If
End Sub
 
Upvote 0
hi

thanks,works well.

I used this one

Code:
[COLOR=#333333]Sub HondaEpcNumber_Click()[/COLOR]

If Cells(13, "B") <> "" Then
        HondaParts.MyPartNumber.Value = Cells(13, "B")
        HondaParts.Show
    Else
        MsgBox "You didn`t enter a Honda Part Number In Cell B13", vbExclamation, "Honda Number - My Number Look Up"
    End If [COLOR=#333333]End Sub[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,222,749
Messages
6,167,958
Members
452,158
Latest member
MattyM

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