macro to run only under certain condition - how?

O

Orion

I've written some code and assigned it to a command button (not the
ActiveX one), which works fine.
It adds a new dataset to a database, once the new information entered
is not part of the database yet.

Is there any way to disable the macro from running, once this newly
entered information is already stored in the database?

Basically I need some code for this:

If G6="not defined yet" then run the macro code
otherwise not

Thanks for your help!

Norbert
 
B

Bob Phillips

Norbert,

One way to do it would be to add a test at the start of the button code that
tests whether the condition has already been met, and exit if true.

I cannot be more specific than that as I do not know what your button code
looks like, or how you determine that the dataeset has already been added,
but you should know that.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
O

Orion

Hi Bob,
I also thought of adding a test at the start of the button code, but I
really don't know how. I'm still a very basic VB user. All I can do is
to record macros and fiddle a little bit about them.

The area to enter new information is 3 cells (B6:D6), which entries I
concatenate and vlookup in the database (patterns!G:H) for existency.

Formula in G6:
=IF(ISERROR(VLOOKUP(CONCATENATE(B6,C6,D6),patterns!G:H,2,FALSE)),"not
defined yet",VLOOKUP(CONCATENATE(B6,C6,D6),patterns!G:H,2,FALSE))

when the entry exists, I get back the previously allocated Pattern
number,
once the entry doesn't exist, I get back the message "not defined yet"

I can see on the result, if the pattern exists or not, so I (with
stress on "I") know, when not to press the button, but the user I'm
writing the spreadsheet for, might not and I have to avoid same
entries with different allocated Pattern numbers (which will be given
in consecutive order for newly entered datasets).


this is my button code:
Sub INPUT_PATTERN()
'
Application.ScreenUpdating = False
Sheets("patterns").Select
Cells.Select
Selection.EntireColumn.Hidden = False
Columns("A:A").Select
Selection.EntireColumn.Hidden = True
Range("B8:H8").Select
Selection.Copy
Selection.Insert Shift:=xlDown
Range("C8:E8").Select
Application.CutCopyMode = False
Selection.ClearContents
Range("H8").Select
Selection.ClearContents
Range("B2:H2").Select
Selection.Copy
Range("B8").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
True, Transpose:=False
Application.CutCopyMode = False
Application.Run "'conversion.xls'!SORT_FABRICS"
Range("B:B,G:G").Select
Range("G1").Activate
Range("C7").Select
Selection.EntireColumn.Hidden = True
Sheets("CONVERSION").Select
End Sub

Hope You can help me now.

Regards,
Norbert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top