Results 1 to 14 of 14

Vba if then statement with multiple cases and wildcards

Threaded View

  1. #1
    Registered User
    Join Date
    09-25-2015
    Location
    Arizona
    MS-Off Ver
    2010
    Posts
    8

    Vba if then statement with multiple cases and wildcards

    https://drive.google.com/file/d/0B9D...ew?usp=sharing

    ^ this is the link to the spreadsheet so you can visually see what is going on.

    What I need:

    A code that searches (RPA!D5 to last row) against the numbers in (Feature Report!Q to last row), giving me the value if contains one of these values. (First Instance only) 65, 64.99, 40, 45, 30, 35, 15, 20, 10, 50 then put that number in (RPV!)

    A code that searches (RPA!D5 to last row) against the numbers in (Feature Report!Q to last row), giving me the value if (Feature Report!AI2 to last row) contains a wildcard such as (*EPTT*) so if it is EPTT05 give me the value next to it (Feature Report!AM) put that number in (RPAA!) I need this to add all the values up. Since one phone number can have multiple instances of the feature MRC.

    A code that copies all the phone numbers from (Smart Report:Q2 to Last Row) and paste them in (RPA:D5 to Last row).






    Below is a code that I Have at the moment. The issue with it, is that it doesn't do Wildcards, and has the static range of 5-3004 rather than 5-last used row. The last used row is still being judged by column D. Once I have the code done once, I will use it as a template to complete the project.

    Option Explicit
    Sub FeatureReportValues()
    Dim last_srcRw As Long, srcRw As Long
    Dim firstAddress As String
    Dim phNum As Range
    
    
    'Set Feature_Report!Q:Q as search range
       With Sheets("Feature Report").Range("Q:Q")
    'Loop through RPA!D5:D3004
        For srcRw = 5 To 3004
    'Make sure the cell is not empty
         If Sheets("RPA").Range("E" & srcRw) <> "" Then
    'Find Phone Number in Feature Report!Q:Q
          Set phNum = .Find(Sheets("RPA").Range("D" & srcRw))
    
    'If match is found, check value in Column AM against list
            If Not phNum Is Nothing Then
             firstAddress = phNum.Address
               Do
                 Select Case Sheets("Feature Report").Range("AM" & phNum.Row)
                  Case 65, 64.99, 40, 45, 30, 35, 15, 20, 10, 50
    
    'If value from list is found, copy value to RPA!V
                    Sheets("RPA").Range("V" & srcRw) = _
                        Sheets("Feature Report").Range("AM" & phNum.Row)
                    Exit Do
                 End Select
    
    'If value from list not found, seach for next ccurrence of same Phone Number
                 Set phNum = .FindNext(phNum)
               Loop While Not phNum Is Nothing And phNum.Address <> firstAddress
            End If
         End If
        Next
       End With
    
    Dim last_srcRw As Long, srcRw As Long
    Dim firstAddress As String
    Dim phNum As Range
    
    
    'Set Feature_Report!Q:Q as search range
       With Sheets("Feature Report").Range("Q:Q")
    'Loop through RPA!D5:D3004
        For srcRw = 5 To 3004
    'Make sure the cell is not empty
         If Sheets("RPA").Range("D" & srcRw) <> "" Then
    'Find Phone Number in Feature Report!Q:Q
          Set phNum = .Find(Sheets("RPA").Range("E" & srcRw))
    
    'If match is found, check value in Column AI against list
            If Not phNum Is Nothing Then
             firstAddress = phNum.Address
               Do
                 Select Case Sheets("Feature Report").Range("AI" & phNum.Row)
                  Case EPUG
    
    'If value from list is found, copy value to RPA!AO
                    Sheets("RPA").Range("AO" & srcRw) = _
                        Sheets("Feature Report").Range("AM" & phNum.Row)
                    Exit Do
                 End Select
    
    'If value from list not found, seach for next ccurrence of same Phone Number
                 Set phNum = .FindNext(phNum)
               Loop While Not phNum Is Nothing And phNum.Address <> firstAddress
            End If
         End If
        Next
       End With
    End Sub
    Last edited by LightKerosene; 09-25-2015 at 04:01 PM. Reason: Thought of something needed.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 01-03-2014, 10:04 AM
  2. Help needed on a macro
    By del1578 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-03-2012, 03:03 AM
  3. EXCEL MACRO is attached. THIS MACRO is needed in ACCESS
    By cooldebi in forum Access Programming / VBA / Macros
    Replies: 1
    Last Post: 11-20-2011, 04:01 PM
  4. [SOLVED] Macro needed to set macro security in Excel to minimum
    By Carl in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-18-2006, 11:40 AM
  5. Macro needed to Paste Values and prevent Macro operation
    By thunderfoot in forum Excel General
    Replies: 1
    Last Post: 06-10-2005, 08:05 PM
  6. [SOLVED] Macro needed to Paste Values and prevent Macro operation
    By thunderfoot in forum Excel General
    Replies: 0
    Last Post: 06-10-2005, 03:05 PM
  7. Macro help needed...
    By Dan E in forum Excel General
    Replies: 6
    Last Post: 01-26-2005, 08: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