+ Reply to Thread
Results 1 to 7 of 7

If function working but not in Macro

  1. #1
    Registered User
    Join Date
    05-16-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    7

    If function working but not in Macro

    I'm exporting data from Access with Invoice info to import into an accounting program. I need to find the account number based on data within different fields of the exported access invoice data to determine what the Account Number is.

    I have the following function, which works when i paste it in a my cell M2 and drag the formula down, but i can't see how to get this working within a macro; I've tried using it on the V column using the range finder:
    Target, Me.Range("V2:V" & Range("A" & Rows.Count).End(xlUp).Row

    The Macro seems to stop at "MF"

    The function i have is:
    =IF(ISNUMBER(FIND("MF",I2)),410,
    IF(ISNUMBER(FIND("Supply",L2)),470,
    IF(ISNUMBER(FIND("Primary",A2)),430,
    IF(ISNUMBER(FIND("Junior",A2)),430
    IF(ISNUMBER(FIND("College",A2)),420,
    IF(ISNUMBER(FIND("Senior",A2)),420,
    IF(ISNUMBER(FIND("Secondary",A2)),420,430)))))))

  2. #2
    Registered User
    Join Date
    05-16-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: If function working but not in Macro

    Ok, have this working within my VBA with the following 6 definitions, but can't add any more?

    How else would i do this?

    Range("M2").Select
    ActiveCell.FormulaR1C1 = _
    "=IF(ISNUMBER(FIND(""MF"",RC[-4])),410,IF(ISNUMBER(FIND(""Supply"",RC[-1])),470,IF(ISNUMBER(IND(""Primary"",RC[-12])),430,IF(ISNUMBER(FIND(""Junior"",RC[-12])),430,IF(ISNUMBER(FIND(""College"",RC[-12])),420,IF(ISNUMBER(FIND(""Senior"",RC[-12])),420,430))))))"

    Selection.AutoFill Destination:=Range("M2:M" & Range("A" & Rows.Count).End(xlUp).Row), Type:=xlFillDefault

  3. #3
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: If function working but not in Macro

    Just a quick guess, because I am not exactly sure what you are trying to achieve, but have you tried to move the full formula to vba and only print the result to the cell. You could use the Case function that will allow you a much larger number than an IF statement.

    abousetta

  4. #4
    Registered User
    Join Date
    05-16-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: If function working but not in Macro

    Ok, thanks

    In a case function how would i query the contents of different cells in the same row to populate my Account Number (Column M)?

    IE:
    I want to use a case like the following to populate the cells in M:
    Case 1 "Supply",RC[-1] (Column L)
    Account No = 470
    Case 2 "Primary",RC[-12] (Column A)
    Account No = 430

    and so on.

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: If function working but not in Macro

    Hi,

    Could you post a dummy sheet? I am just thick skulled right now and my brain cells responsible for imagination are on holidays.

    abousetta

    P.S. Code tags needed around code. I just got hounded by one of the moderators because I posted one row of code without code tags.

  6. #6
    Registered User
    Join Date
    05-16-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: If function working but not in Macro

    Cheers, i've attached a file

    I want to populate Account No with 410 if Column K (Description) contains MT
    or Account Number with 470 if Column H (Customer PO) contains Supply
    or Account Number with 430 if Column A (Co./Last Name) contains Primary
    Last edited by KarlSm; 05-23-2011 at 07:18 PM.

  7. #7
    Registered User
    Join Date
    05-16-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: If function working but not in Macro

    Anyone able to help with this case function?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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