+ Reply to Thread
Results 1 to 11 of 11

Transform Excel IF Function to VBA

  1. #1
    Registered User
    Join Date
    11-08-2015
    Location
    London
    MS-Off Ver
    2003 & 2010
    Posts
    6

    Transform Excel IF Function to VBA

    Good day,

    Can anyone help to transform this to VBA ?


    =IF(AND(OR(F14=700;F14=705;F14=707;F14=710;F14=720;F14=730);AND(E14<>"INL";E14<>"FDK";E14<>"FDP";E14<>"FG";E14<>"RMB"));"ADV";
    IF(AND(OR(F14=732;F14=734;F14=750);AND(E14<>"INL";E14<>"FDK";E14<>"FDP";E14<>"FG";E14<>"RMB"));"DOC";
    IF(AND(OR(F14=103;F14=199;F14=202;F14=742;F14=747);AND(E14<>"INL";E14<>"FDK";E14<>"FDP";E14<>"FG";E14<>"RMB"));"PAY";
    IF(AND(OR(F14=740;F14=742;F14=747;F14=799;);E14="RMB");"RMB";""))))


    Thanks a lot. :)

  2. #2
    Registered User
    Join Date
    03-16-2009
    Location
    Michigan
    MS-Off Ver
    2013 64 Bit
    Posts
    1

    Re: Transform Excel IF Function to VBA

    Do you want the macro to write the equation to a cell on the worksheet or do you want the equivalent conditional if statement in VBA syntax?

  3. #3
    Registered User
    Join Date
    11-08-2015
    Location
    London
    MS-Off Ver
    2003 & 2010
    Posts
    6

    Re: Transform Excel IF Function to VBA

    I want the equivalent conditional if statement in VBA syntax.

    Thanks in advance.

  4. #4
    Registered User
    Join Date
    11-08-2015
    Location
    London
    MS-Off Ver
    2003 & 2010
    Posts
    6

    Re: Transform Excel IF Function to VBA

    IMAGE.jpg

    Here's the snapshoot of the excel file. The result of Column O will depends on Column E & F.

    Hope to here from you soon.

  5. #5
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    419

    Re: Transform Excel IF Function to VBA

    I think this is what you are asking for - should get you started at least:

    Please Login or Register  to view this content.
    Last edited by mgs73; 11-11-2015 at 12:13 AM.

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Transform Excel IF Function to VBA

    Try
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-08-2015
    Location
    London
    MS-Off Ver
    2003 & 2010
    Posts
    6

    Re: Transform Excel IF Function to VBA

    Image removed. Sorry
    Last edited by Koyish; 11-14-2015 at 02:52 AM.

  8. #8
    Registered User
    Join Date
    11-08-2015
    Location
    London
    MS-Off Ver
    2003 & 2010
    Posts
    6

    Re: Transform Excel IF Function to VBA

    The Coding are just working on the row 14 only. How to apply on the entire Range O?

    Quote Originally Posted by mgs73 View Post
    I think this is what you are asking for - should get you started at least:

    Please Login or Register  to view this content.

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Transform Excel IF Function to VBA

    Working here,

    It is always best to upload a small sample workbook. Picture doesn't help at all.

  10. #10
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    419

    Re: Transform Excel IF Function to VBA

    Try this:
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    11-08-2015
    Location
    London
    MS-Off Ver
    2003 & 2010
    Posts
    6

    Re: Transform Excel IF Function to VBA

    Thanks for the suggestion guys~~

    At last, i complete the coding in a longer way.



    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Y = ActiveCell.Row

    If Not Intersect(ActiveCell, Range("E3:E500")) Is Nothing Then
    Call Team
    End If

    End Sub
    Sub Team()

    Dim wsMaster As Worksheet
    Dim lastRowM As Long
    Dim SR_E As Range
    Dim SR_F As Range
    Dim DestinationRange As Range
    Dim X As Integer

    Set wsMaster = ThisWorkbook.Sheets("Input SWIFT")

    lastRowM = wsMaster.Range("A" & Rows.Count).End(xlUp).Row

    Set SR_E = wsMaster.Range("E3:E" & lastRowM)
    Set SR_F = wsMaster.Range("F3:F" & lastRowM)
    Set DestinationRange = wsMaster.Range("O3:O" & lastRowM)


    For X = 1 To SR_E.Count

    'Manual Assign1 700 705 707 710 720 730
    If SR_F(X, 1) <> 700 Or SR_F(X, 1) <> 705 Or SR_F(X, 1) <> 707 Or SR_F(X, 1) <> 710 Or SR_F(X, 1) <> 720 Or SR_F(X, 1) <> 730 Then
    DestinationRange(X, 1) = ""
    End If

    'Manual Assign2 732 734 750
    If SR_F(X, 1) <> 732 Or SR_F(X, 1) <> 734 Or SR_F(X, 1) <> 750 Then
    DestinationRange(X, 1) = ""
    End If

    'Manual Assign3 103 199 202 299 742 747
    If SR_F(X, 1) <> 103 Or SR_F(X, 1) <> 199 Or SR_F(X, 1) <> 202 Or SR_F(X, 1) <> 299 Or SR_F(X, 1) <> 742 Or SR_F(X, 1) <> 747 Then
    DestinationRange(X, 1) = ""
    End If

    'Advising 700 705 707 710 720 730
    If SR_F(X, 1) = 700 Or SR_F(X, 1) = 705 Or SR_F(X, 1) = 707 Or SR_F(X, 1) = 710 Or SR_F(X, 1) = 720 Or SR_F(X, 1) = 730 Then
    DestinationRange(X, 1) = "ADV"
    End If

    'Doc Checking 732 734 750
    If SR_F(X, 1) = 732 Or SR_F(X, 1) = 734 Or SR_F(X, 1) = 750 Then
    DestinationRange(X, 1) = "DOC"
    End If

    'Payment 103 199 202 299 742 747
    If SR_F(X, 1) = 103 Or SR_F(X, 1) = 199 Or SR_F(X, 1) = 202 Or SR_F(X, 1) = 299 Or SR_F(X, 1) = 742 Or SR_F(X, 1) = 747 Then
    DestinationRange(X, 1) = "PAY"
    End If

    'Out of Scope INL FDK FDP FGH RMB
    If SR_E(X, 1) = "INL" Or SR_E(X, 1) = "FDK" Or SR_E(X, 1) = "FDP" Or SR_E(X, 1) = "FGH" Or SR_E(X, 1) = "RMB" Then
    DestinationRange(X, 1) = ""
    End If

    'Reimbursement
    If SR_E(X, 1) = "RMB" And SR_F(X, 1) = 700 Then
    DestinationRange(X, 1) = ""
    ElseIf SR_E(X, 1) = "RMB" Then DestinationRange(X, 1) = "RMB"
    End If

    Next X

    End Sub

+ 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. Using SQL to transform Excel data
    By cyiangou in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-02-2015, 05:46 AM
  2. [SOLVED] transform formula for excel 2000
    By max_max in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-28-2013, 10:07 AM
  3. Transform a too long Excel formula into a Macro
    By buch84 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-26-2010, 10:52 AM
  4. Replies: 1
    Last Post: 12-14-2005, 05:35 AM
  5. Replies: 5
    Last Post: 10-11-2005, 02:22 PM
  6. Replies: 2
    Last Post: 08-31-2005, 12:33 PM
  7. [SOLVED] how do I transform data from excel to spss?
    By Student in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-28-2005, 02:06 PM

Tags for this Thread

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