+ Reply to Thread
Results 1 to 19 of 19

VBA/Macro Match

  1. #1
    Registered User
    Join Date
    06-02-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    15

    VBA/Macro Match

    Hi all. I'm writing a macro for a spreadsheet for billing my customers' calls. As I've found out today procedures can only be 64kb.. I'm writing my '=IFS' statement but it's taking forever, here's a part of it:

    Please Login or Register  to view this content.
    That's just 15 of the area codes.. there are 477 in total

    What I'd like to do in H is say, for example is: 'look at column J, if it matches anything in column O, take the value in the cell to the right of the matched cell in O and multiply it by the appropriate row in F'. I'm hoping that's possible instead of having to type out everything. Here's a pic of what a sheet looks like (With sensitive bits removed):
    Billing.PNG

    The original code, before I started tweaking it for this large customer (I've typed everything out for one of our smaller customers and it works great):

    Please Login or Register  to view this content.
    Hope this makes sense, I've managed to stumble my way through it so far but am now a bit stuck! I'll happily buy anyone who can help a beer!

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,882

    Re: VBA/Macro Match

    Can you upload sample workbook that represent your data set? With sensitive data sanitized.

  3. #3
    Registered User
    Join Date
    06-02-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    15

    Re: VBA/Macro Match

    https://app.box.com/s/b9sau8s3ci2wf47r0wd5n335k46aej82 That should be the workbook with all sensitive data removed.

    It's the code for the small customer but the principle of needing to check cells in a column against another is the same. Cheers.

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA/Macro Match

    In H3:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    then copy down?

    or if you only want 3 decimals:

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  5. #5
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,882

    Re: VBA/Macro Match

    If you want to do it in VBA and only put values into the range.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    06-02-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    15

    Re: VBA/Macro Match

    Thanks guys. I'll give it a go next week and report back.

  7. #7
    Registered User
    Join Date
    06-02-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    15

    Re: VBA/Macro Match

    Arkadi, I tried the lookup but it threw an error back at me, I'm sure I'm just putting it in the wrong section.

    CK76, when I added that sub it filled H with the same value all the way down. H needs to change depending on the code matched in J and the value of F. The code needs to match the value of J to O, which takes the value of the corresponding P cell and then multiplies it by the correct F value for the correct row.

    Hope that makes sense.

  8. #8
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,882

    Re: VBA/Macro Match

    Hmm? It worked fine on my end.

    See sample attached.
    Attached Files Attached Files
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  9. #9
    Registered User
    Join Date
    06-02-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    15

    Re: VBA/Macro Match

    Oh right, thanks. Where in my code should i insert the new sub? Below is the code (I would attach but the button doesn't seem to work for me).

    It does a bunch of sorting and inserting reference cells etc.

    Please Login or Register  to view this content.

  10. #10
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,882

    Re: VBA/Macro Match

    Just stick at the bottom or in separate module. It really does not matter.

  11. #11
    Registered User
    Join Date
    06-02-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    15

    Re: VBA/Macro Match

    Still can't get it to work, sorry.

    Here's what I have:

    https://app.box.com/s/4o7th3f8yy3dg5py62omirlaggp8d3ht

    In case the Macro isn't on the sheet then this is what it looks like:

    https://app.box.com/s/r9sumdl61t1xrklipm5f247mb45rmr5x

    The Call function just has CK76's code in it with the sub name changed to Calc444, no other changes. Not sure what I'm missing..

  12. #12
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,882

    Re: VBA/Macro Match

    Which sheet is active when you run the code?

  13. #13
    Registered User
    Join Date
    06-02-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    15

    Re: VBA/Macro Match

    Sheet 15, from there it should take the columns I need, paste them into a new sheet (16), insert the reference cells in columns O & P, do a few bits with decimals etc. then carry out the calculation in H, which was previously an =IFS statement, looked like this:

    Please Login or Register  to view this content.
    Copy that statement for 500 or so rows in H, this tells us how much we need to bill the customer for the call in that row. The macro then copies the columns I need and pastes them into the final new sheet (17) and tidies it up a bit. We then export that into a word document.

  14. #14
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,882

    Re: VBA/Macro Match

    Ok, give me bit of time to rewrite your code. It's bit inefficient and and bloats file size.

    Your file in itself should not be any more than couple of hundred Kb, but due to unnecessary format etc, bloating to 9mb in size.

  15. #15
    Registered User
    Join Date
    06-02-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    15

    Re: VBA/Macro Match

    Thanks CK. I don't know how to write in VB really, so I originally recorded the Macro by using the record action and actually typing the stuff out/carrying out the actions, then later edited it to tweak it.

    Let me know if you have one of those 'buy me a beer' links!

  16. #16
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,882

    Re: VBA/Macro Match

    Found the culprit that replicated same number in column. Your Proc3 had following.
    Please Login or Register  to view this content.
    This would overwrite the values in range with value in "H3".

    By the way, why do you use code to write values to O:P range? It's far better to maintain the list in separate sheet and read from there.

    I'll have something for you in few hours (I'm headed into meeting now).

  17. #17
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,882

    Re: VBA/Macro Match

    Here you go. Only part I wasn't sure about was your last sort operation.

    Which column(s) should it be sorted on?

    Notes:
    1. Raw is the original sheet
    2. List is the list that contains list of Charge Code and corresponding cost (if you need to add more, add to bottom of the list, code will auto adjust)
    3. Output is where your intermediate result goes. Then add another sheet for your final out put.
    4. Ranges are all dynamic now to avoid formatting entire column range unnecessarily.
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    06-02-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    15

    Re: VBA/Macro Match

    Wow, that's amazing. Thank you CK! That's leagues better than what I was able to do. Many thanks, I've added rep.

  19. #19
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,882

    Re: VBA/Macro Match

    You are welcome and thanks for the rep

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA macro to match information from one column with another and delete rows no match
    By Renejorgensen in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-17-2016, 04:07 PM
  2. Macro to match Debits and Credits, verifying four columns of each debit and credit match
    By forcedto register in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 09-22-2016, 05:28 PM
  3. Replies: 2
    Last Post: 01-26-2015, 04:53 AM
  4. Replies: 0
    Last Post: 09-21-2013, 09:03 PM
  5. [SOLVED] Macro to match decimals, write only decimal match
    By ricklou in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-27-2013, 03:04 PM
  6. [SOLVED] macro copy section with match, but put a zero when its a no match...HELP!!
    By extremis in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-29-2013, 01:46 AM
  7. Macro to copy paste if match not found "go to next"
    By HawksOkeyoJr in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-07-2013, 05:28 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1