Jump to content

Calculations to create Macro button in Excel for 2 conditional scenarios


Recommended Posts

After starting my previous thread "What formula will work to acieve this result" I decided to post this new thread because I have changed my mind and will now be using the external Excel file that the "Extract Data" creates to do my calculations.

 

Here's what I would like to do: create a Macro [button] in Excel with the following conditions:

*

Sample of excel spreadsheet:

*

MANUF No SUB No. DESCRIPTION ** UNIT QUANTITY

A1234 94456 TYPE A, XXXX XXX * * * * EA ** * * * 45

A4235 20374 YA1AM, XXXXXXXXXX * **EA ** * * * 55

A1482 31375 TYPE B, XXXXXXXXX * * * EA ** * * * 33

A1461 51725 A1AAM, XXXXXXXXXX * * EA ** * * * 67

A1356 21873 TYPE A, XXXXXXXXX * * * EA ** * * * 24

 

1. * * * CONDITION #1:

IF "DESCRIPTION" TAB ["C" COLUMN] CONTAINS "TYPE A" AS PART OF TEXT/DESCRIPTION, TAKE THE "QUANTITY" TAB ["E" COLUMN] SPECIFIED ON THAT PARTICULAR ROW AND DIVIDE IT BY 20, ROUNDED UP TO NEAREST ONE.*

 

2. * * * CONDITION #2:

IF "DESCRIPTION" ["C" COLUMN] CONTAINS "TYPE B" AS PART OF TEXT/DESCRIPTION, TAKE THE "QUANTITY" SPECIFIED ON THAT PARTICULAR ROW ["E" COLUMN] AND DIVIDE IT BY 10, ROUNDED UP TO NEAREST ONE.

 

3. * * * AUTOMATICALLY SAVE THE EXCEL FILE AFTER THIS MACRO HAS BEEN UTILIZED.

 

I will really appreciate a Speedy solution....soon ;)

Link to comment
Share on other sites

Thank you for your help Mircea.

 

I tried pasting that code in excel [right clicking on an object, assign macro] but it gives me an error [Microsoft Visual Basic...Compile error: Expected: line number or label or statement or end of statement]. I don't know if I did this correctly as this is my first time working on codes. Can you please guide me thru'?

 

FYI, in your new code please note that the "Description" starts from row C2 onwards and the "Quantity" starts from E2 onwards which is the one to divide by either 20 or 10 [per conditions I specified at the start of this thread], rounded by nearest one and replaced in the "Quantity" column/row for that particular condition.

 

I was trying to attach the excel file or gif file to give you a better picture of the scenario but was not successful.

 

Regards,

Link to comment
Share on other sites

My example is to be used as a cell formula; I'm afraid that you didn't stated that you were looking for a VBA example.

Link to comment
Share on other sites

Sorry about that. Would VBA be better in automating the series of these tasks? If so, please provide a solution [i don't mind either one is fine as long as it works] based on the criteria I have provided above. My preferance is to have a Macro button and have all these tasks embedded in it.

 

Please note that I donot require the roundup as the quantity has already been set to roundup in the AutoCAD Table.

 

Thank you.

Edited by colors
Forgot to mention about not needing "roundup" in the formula/code
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...