+ Reply to Thread
Results 1 to 16 of 16

VBA to extract account number where ref and amount matches

  1. #1
    Spammer
    Join Date
    08-20-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    221

    VBA to extract account number where ref and amount matches

    I have reference numbers in Col G and values in Col I on Workbook "sales by region"


    I would like to extract the account number in Col J , on workbook "sales by region" from workbook "Data sales import" (source workbook) in col G where the ref No. in Col A and the value in Col J matches the ref in Col G and the value in Col I (these are positive values ) and the value in Col H <> 0


    If the value in Col I is in credit for eg -8500, then the account number to be extracted in Col G in the source workbook ,is when the Ref in Col G & negative value in Col I , matches the Ref in Col A and the value in col K (col K is a credit column but the values do not have a minus sign in front of them) and the value in Col H <> 0


    Your assistance in this regard is most appreciated
    Attached Files Attached Files
    Last edited by flupsie; 07-01-2018 at 11:55 AM.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to extract account number where ref and amount matches

    You number values gave me some misery, but this should do it.

    Please Login or Register  to view this content.
    If you have a large data base it could take a few seconds.
    Last edited by JLGWhiz; 07-01-2018 at 08:11 PM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Spammer
    Join Date
    08-20-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    221

    Re: VBA to extract account number where ref and amount matches

    Thanks very much for your help. Sorry my number values gave you some misery. It was rather complex and not easy to explain

    I made a minor change to your code as you inadvertentely left out the file tpe of the excel file

    Please Login or Register  to view this content.

    once i made the change above , your code worked perfectly.


    Your assistance is highly appreciated
    Last edited by flupsie; 07-01-2018 at 11:02 PM.

  4. #4
    Spammer
    Join Date
    08-20-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    221

    Re: VBA to extract account number where ref and amount matches

    I retested the data and need a change that I overlooked when advising you what my requirements were

    The only change is where Col H in the workbook "sales by region.xls has a zero value , even where there is a match in my requirements in Post # 1, then in that instance no account number to be extracted

    I have attached my workbook, showing what the final result should look like-see col L "manual result. I have also tried to explain below in some detail





    where the values in Col H is zero in the workbook "sales by region.xls" on sheets "imported data , and the ref in Col G and the positive Value in Col I matches the Ref in Col A and Value in Col J in the the workbook "Data Sales Import.xlsm", then the account number must not be extracted

    The same will apply to the negative values i.e where the values in Col H is zero in the workbook "sales by region.xls" on sheets "imported data , and the ref in Col G and the and the negative Value in Col I matches the Ref in Col A and Value in Col K in the the workbook "Data Sales Import.xlsm", then the account number must not be extracted


    Your assistance in amending the code is most appreciated






    Where the ref no. in Col G and values in Col I on Workbook "sales by region.xlsm" matches
    Attached Files Attached Files

  5. #5
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to extract account number where ref and amount matches

    Please Login or Register  to view this content.

  6. #6
    Spammer
    Join Date
    08-20-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    221

    Re: VBA to extract account number where ref and amount matches

    thanks for the help and for indicating the change in red

  7. #7
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to extract account number where ref and amount matches

    Quote Originally Posted by flupsie View Post
    thanks for the help and for indicating the change in red
    You're welcome. Don't forget to mark the thread as solved.
    Regards, JLG

  8. #8
    Spammer
    Join Date
    08-20-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    221

    Re: VBA to extract account number where ref and amount matches

    I have retested the code with some additional data and the account numbers highlighted in yellow in the column N "Manual Extraction" are not being extracted


    Please test & kindly amend your code
    Attached Files Attached Files

  9. #9
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to extract account number where ref and amount matches

    Revised. I have looked at the data again and see that the code should have detected the values in column I for those items highlighted. I do not have an immeditate explanation for the anomally. I will look into it further and if I find an explanation, I will post it here. Please do not send more PMs.
    Last edited by JLGWhiz; 07-12-2018 at 09:41 PM.

  10. #10
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to extract account number where ref and amount matches

    I see what is causing the problem and will address it tomorrow. If I can fix it, I will post the code on this thread.
    Last edited by JLGWhiz; 07-12-2018 at 09:51 PM.

  11. #11
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to extract account number where ref and amount matches

    In the sheets downloaded from post #4, column J of sheets("Imported Data") shows 'Cat' instead of 'Account Number' which was in the original example in Post #1. This code puts the "extracted" values in column J. If you want to put the value in column M then you will need to change the offset from 1 to 3. This tested Ok in my set up, but you need to verify it with your database.

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,722

    Re: VBA to extract account number where ref and amount matches

    I am a friend of Flupsie. He advised me to let you know on his behalf that your amended code is working perfectly.

    He is unable to access this site for some unknown reason. Je jhas emailed the administrators and waiting for a reponse

  13. #13
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to extract account number where ref and amount matches

    Quote Originally Posted by Howardc1001 View Post
    I am a friend of Flupsie. He advised me to let you know on his behalf that your amended code is working perfectly.

    He is unable to access this site for some unknown reason. Je jhas emailed the administrators and waiting for a reponse
    Thanks for the info,
    Regards, JLG

  14. #14
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,722

    Re: VBA to extract account number where ref and amount matches

    Hi JLJ

    Flupsie is still unable to access the Forum and is getting an IT person to come over this week to come have a look

    He said what you have done so far is working 100%, but when testing another workbook he found a few exceptions to his spec and he neds the code to be amended based on the following


    1) Where the ref no. in Col G matches Col A (Source file) and Value in Col I is positive and value in Col H <> 0 and there is no match in value for same ref, then find the value in Col J that matches Col H that is a few rows above it and extract the Account no. from Col G in same row and paste it in Col M (destination File)
    2) Where the ref in Col G (destination File) does not Match the Ref No. in Col A (Source File) and the value in Col I is positive and col H <> 0 then find value in Col J that is the closest to it and extract the account number in Col G and paste it in Col M (destination file)

    3) Where the ref in Col G (destination File) does not Match the Ref No. in Col A (Source File) and the value in Col I is negative and col H <> 0 then find value in Col K that is the closest to it and extract the account number in Col G and paste it in Col M (destination file)

    4) Where the ref No. appears as a date in Col G (destination file) for eg 16-Oct (is actually 16/10/2018) , then exclude the year when matching ref No.to Col A in source file and then match the Value in Col I if positive and value in Col H <> 0 with Value in Col J and extract account no. from Col G in same row as match and paste in Col M (source File)

    5) Where the ref No. appears as a date in Col G (destination file) for eg 16-Oct (is actually 16/10/2018) , then exclude the year when matching ref No.to Col A in source file and then match the Value in Col I if negative and value in Col H <> 0 with Value in Col K and extract account no. from Col G in same row as match and paste in Col M (source File)


    He said when you get a chance, if you kindly amend the code per the above. If too comlex, then he said he wil manually have to extractthe account number for the additional items where the acciunt number is not being automatically extracted

  15. #15
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to extract account number where ref and amount matches

    flupsie will have to post to another forum unless he can get one of the moderators to remove the spammer flag on his avatar. I will not provide any more assistance on this thread until he reconciles with the forum administrators.
    Last edited by JLGWhiz; 07-19-2018 at 08:29 AM.

  16. #16
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,722

    Re: VBA to extract account number where ref and amount matches

    Fully Under JLG

+ 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. [SOLVED] If Account column value matches, add/subtract to a cell value
    By shivers in forum Excel General
    Replies: 4
    Last Post: 07-19-2017, 12:42 PM
  2. search 2 criteria and if it matches give me the number of matches
    By sxch12 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-14-2017, 03:16 PM
  3. IF Statement that will assign account types based on "account number"
    By aladdin16 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-08-2014, 05:04 PM
  4. Script to Extraxt Zipped Files
    By scarydan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-26-2014, 05:29 AM
  5. if Account number = return Account Name
    By mom2carisa in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 09-04-2013, 06:03 PM
  6. Return Account Nickname if Account Number Matches
    By spacle in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-03-2013, 11:04 AM
  7. [SOLVED] How to censor account numbers based on how many characters are in the account number
    By Mcorydon in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-25-2013, 01:06 PM

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