Results 1 to 10 of 10

Replace multiple "If Then" with "For" loop

Threaded View

  1. #1
    Registered User
    Join Date
    06-17-2014
    Location
    United States
    MS-Off Ver
    2007
    Posts
    9

    Replace multiple "If Then" with "For" loop

    Can anyone please tell me how to use "for" loop for this?

    Function AFIX(cn As String, prem1 As Double, income1 As Double, Optional prem2 As Variant, Optional income2 As Variant, Optional prem3 As Variant, Optional income3 As Variant, Optional prem4 As Variant, Optional income4 As Variant
    
    If IsMissing(prem2) Then
        prem2 = ""
    Else
        If ((prem2 <> 20000) And (prem2 <> 25000) And (prem2 <> 50000) And (prem2 <> 100000) And (prem2 <> 150000) And (prem2 <> 200000) And (prem2 <> 250000)) Then
           MsgBox "Error: Enter a valid premium"
           Exit Function
        End If
    End If
    
    If IsMissing(prem3) Then
        prem3 = ""
    Else
        If ((prem3 <> 20000) And (prem3 <> 25000) And (prem3 <> 50000) And (prem3 <> 100000) And (prem3 <> 150000) And (prem3 <> 200000) And (prem3 <> 250000)) Then
           MsgBox "Error: Enter a valid premium"
           Exit Function
        End If
    End If
    
    If IsMissing(prem4) Then
        prem4 = ""
    Else
        If ((prem4 <> 20000) And (prem4 <> 25000) And (prem4 <> 50000) And (prem4 <> 100000) And (prem4 <> 150000) And (prem4 <> 200000) And (prem4 <> 250000)) Then
           MsgBox "Error: Enter a valid premium"
           Exit Function
        End If
    End If
    Last edited by checkltout; 06-19-2014 at 08:13 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. using for loop to replace if-then-else
    By bored in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-31-2013, 12:23 AM
  2. Find & replace loop over multiple columns
    By bigcol77 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-01-2012, 02:24 PM
  3. replace multiple ifs in a do.. loop request
    By nicer2011 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-12-2011, 06:14 PM
  4. Best Loop to replace multiple strings
    By ker9 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-22-2011, 04:38 PM
  5. Replace using Do loop
    By Dave B in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-29-2005, 03:40 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