Run macro only if 2 criteria apply

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
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 a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
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,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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