Results 1 to 12 of 12

VBA script to extract data based on multiple columns

Threaded View

  1. #1
    Forum Contributor
    Join Date
    09-13-2013
    Location
    Saudi Arabia
    MS-Off Ver
    2010, 2013
    Posts
    192

    VBA script to extract data based on multiple columns

    Hello Again,

    Below is my script it is working find on single column but i need to have combination of multiple columns but i failed.

    Can someone enhance the below script. Copy of workbook is attached for your reference.

    Problem Here
    myval = data(i, 15)
            If Not myval Like "J03*" Then
            'If Not myval Like "J03*" Then
        Else
            If errstr = "" Then errstr = "Error 2" Else errstr = errstr & ", " & "Error 2"
            result(j, 15) = temp
        End If
    Original code:-
    
    Option Compare Text
    
    Sub ProblemLog()
    
    With Application
            .DisplayAlerts = False
            .ScreenUpdating = False
            .EnableEvents = False
        End With
    
    Dim data, result, rng2color As Range, rcount As Long, colcount As Long, j As Long, i As Long, myval, errstr As String
    Const temp = "#%$#"
    
    If ActiveSheet.Name = "Claims Data" Or ActiveSheet.Name = "Template" Then
    
    data = Range("A1", Cells(Rows.Count, 1).End(xlUp)).Resize(, 46)
    
    rcount = UBound(data)
    colcount = UBound(data, 2)
    
    ReDim result(1 To rcount, 1 To colcount + 1)
    
    result(1, 1) = "Provider"
    result(1, 2) = "Box Number"
    result(1, 3) = "Claim Number"
    result(1, 4) = "Treatment Date"
    result(1, 5) = "Discharge Date"
    result(1, 6) = "Benefit Type"
    result(1, 7) = "Member PIN"
    result(1, 8) = "Member Name"
    result(1, 9) = "Member Class"
    result(1, 10) = "Policy  Number"
    result(1, 11) = "Policy Holder Name"
    result(1, 12) = "Policy Benefit"
    result(1, 13) = "Network Type"
    result(1, 14) = "Policy Type"
    result(1, 15) = "Diagnosis"
    result(1, 16) = "Gross"
    result(1, 17) = "Discount"
    result(1, 18) = "Deductible"
    result(1, 19) = "Rejected Amount"
    result(1, 20) = "Approved Amount"
    result(1, 21) = "Total difference"
    result(1, 22) = "Created By "
    result(1, 23) = "Created Date"
    result(1, 24) = "Created Time"
    result(1, 25) = "Pre-Auth Limit"
    result(1, 26) = "Approval Number"
    result(1, 27) = "Approval Date"
    result(1, 28) = "Auditor"
    result(1, 29) = "Difference Reason"
    result(1, 30) = "Description"
    result(1, 31) = "Claim Caution"
    result(1, 32) = "Marital Status"
    result(1, 33) = "Gender"
    result(1, 34) = "Insured Type"
    result(1, 35) = "Age"
    result(1, 36) = "Chronic"
    result(1, 37) = "Pre Existing"
    result(1, 38) = "Fraud"
    result(1, 39) = "Emergency"
    result(1, 40) = "Follow Up"
    result(1, 41) = "File Number"
    result(1, 42) = "Notes"
    result(1, 43) = "Claim Status"
    result(1, 44) = "Recovery Amount"
    result(1, 45) = "Approved VAT Amount"
    result(1, 46) = "Rejected VAT Amount"
    result(1, 47) = "Remarks"
    
    
    j = 1
    
    For i = 2 To rcount
        j = j + 1
    
        myval = data(i, 15)
        If Not myval Like "Z00*" Then
        Else
            errstr = "Error 1"
            result(j, 15) = temp
        End If
        
        myval = data(i, 15)
            If Not myval Like "J03*" Then
            'If Not myval Like "J03*" Then
        Else
            If errstr = "" Then errstr = "Error 2" Else errstr = errstr & ", " & "Error 2"
            result(j, 15) = temp
        End If
    
        If errstr <> "" Then
            For n = 1 To colcount
                result(j, n) = result(j, n) & data(i, n)
            Next
            result(j, 47) = errstr
            errstr = ""
        Else: j = j - 1
        End If
    Next
    Application.ScreenUpdating = 0
    Application.ReplaceFormat.Interior.ColorIndex = 6
    
    '*******************************************************************************************************************************************************************
    
    Sheets.Add(Before:=Sheets("Claims Data")).Name = "ErrorLog"
    With Worksheets("ErrorLog")
        .Range("a1").Resize(j, colcount + 1) = result
        With .Range("a1").Resize(, colcount + 1)
            .Interior.ColorIndex = 55
            .Font.ColorIndex = 2
            .Font.Bold = 1
            .HorizontalAlignment = xlCenter
        End With
        With .UsedRange
            .Font.Name = "Calibri"
            .Font.Size = 9
            .Borders.LineStyle = xlContinuous
            .Offset(, 1).Resize(, 47).Replace what:=temp, replacement:="", lookat:=xlPart, ReplaceFormat:=True
            .Offset(, 1).Resize(, 47).Replace what:=temp, replacement:="", lookat:=xlPart
        End With
    End With
    
    Else
    Response = MsgBox("This option will not for sheet: " & UCase(ActiveSheet.Name) & vbCrLf + "Please select/active below worksheets to use this option." _
    + vbCrLf + " " + vbCrLf + "1. DATA Worksheet" + vbCrLf + "2. TEMPLATE Worksheet" + vbCrLf + " " + vbCrLf + "                                      Abdul Aleem - Lets Make Life Easier...", vbOKOnly + vbInformation, "Underwriting Department")
    
    End If
    
    '*******************************************************************************************************************************************************************
    
    With Application
            .DisplayAlerts = True
            .ScreenUpdating = True
            .EnableEvents = True
        End With
        
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Extract data from table based on criteria applied to multiple columns
    By Feremartinez in forum Excel General
    Replies: 9
    Last Post: 11-21-2018, 12:34 PM
  2. [SOLVED] Extract Unique values based from multiple columns
    By kobiashi in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 06-14-2018, 10:10 AM
  3. [SOLVED] vba script to calculate data across multiple columns
    By pchappo in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-14-2017, 04:50 AM
  4. [SOLVED] Extract data based on criteria from multiple columns
    By madmoo84 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-08-2017, 07:29 AM
  5. [SOLVED] macro needed to extract specific columns out of multiple columns with their row data
    By genetist in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-07-2014, 12:49 AM
  6. Replies: 11
    Last Post: 10-30-2013, 05:04 AM
  7. Extract Data based on conditions on multiple columns
    By checkoncomp in forum Excel General
    Replies: 6
    Last Post: 07-03-2013, 01:54 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