ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Run macro only if Field E10 = "WO ID" and AB10 = "Spec Sizing" (https://www.excelbanter.com/excel-discussion-misc-queries/180236-run-macro-only-if-field-e10-%3D-wo-id-ab10-%3D-spec-sizing.html)

ldiaz

Run macro only if Field E10 = "WO ID" and AB10 = "Spec Sizing"
 
hello all.

I want to run a macro only:
if Field E10 = "WO ID" and AB10 = "Spec Sizing"

if fields are different then it must show a message saying that the file is
not the correct one.

my macro needs Ctrl + m key to run,

and start llike this:

Sub Shipping()
' Keyboard Shortcut: Ctrl+m
'start Macro
Statement
'End macro
End Sub

where do I need to put the code?


please help
Thanks in advanced

--
Lorenzo DÃ*az
Cad Technician

FSt1

Run macro only if Field E10 = "WO ID" and AB10 = "Spec Sizing"
 
hi
to run, the macro must be in an open file.
put it in a general module in the file that you will be running the macro.
open the vb editor....Alt+F11
if the code window (big one, far right) is gray....
on the tool bar...
insertmodule
paste your code in the code window. save the file.

Sub yoursub()
if range("E10").value ="WO ID" and range("AB10").value = "Spec Sizing" then
your code here
else
msgbox "wrong file!"
end if
end sub

alter possiblity....
Sub yoursub()
if activeworkbook.name = yourworkbookname then
your code here
else
msgbox "wrong file!"
end if
end sub

regards
FSt1

"ldiaz" wrote:

hello all.

I want to run a macro only:
if Field E10 = "WO ID" and AB10 = "Spec Sizing"

if fields are different then it must show a message saying that the file is
not the correct one.

my macro needs Ctrl + m key to run,

and start llike this:

Sub Shipping()
' Keyboard Shortcut: Ctrl+m
'start Macro
Statement
'End macro
End Sub

where do I need to put the code?


please help
Thanks in advanced

--
Lorenzo DÃ*az
Cad Technician


ldiaz

Run macro only if Field E10 = "WO ID" and AB10 = "Spec Sizing"
 
That's great,
it works perfectly


Thanks

--
Lorenzo DÃ*az
Cad Technician


"FSt1" wrote:

hi
to run, the macro must be in an open file.
put it in a general module in the file that you will be running the macro.
open the vb editor....Alt+F11
if the code window (big one, far right) is gray....
on the tool bar...
insertmodule
paste your code in the code window. save the file.

Sub yoursub()
if range("E10").value ="WO ID" and range("AB10").value = "Spec Sizing" then
your code here
else
msgbox "wrong file!"
end if
end sub

alter possiblity....
Sub yoursub()
if activeworkbook.name = yourworkbookname then
your code here
else
msgbox "wrong file!"
end if
end sub

regards
FSt1

"ldiaz" wrote:

hello all.

I want to run a macro only:
if Field E10 = "WO ID" and AB10 = "Spec Sizing"

if fields are different then it must show a message saying that the file is
not the correct one.

my macro needs Ctrl + m key to run,

and start llike this:

Sub Shipping()
' Keyboard Shortcut: Ctrl+m
'start Macro
Statement
'End macro
End Sub

where do I need to put the code?


please help
Thanks in advanced

--
Lorenzo DÃ*az
Cad Technician



All times are GMT +1. The time now is 01:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com