Excel Help Please

jsomer2000

Board Regular
Joined
Jul 12, 2007
Messages
50
This may be a simple procedure to do but I need some help as I can't remember

I have basic spreadsheet with 3 tabs of data

Tab 1 - Headings

Claim Number
Total1
Total2
Total3

Tab 2 - Headings

Claim Number
Description
Code 1

Tab 3 - Headings

Claim Number
Numbers
Percentage

I want to create a new tab that sorts and matches the data by the claim number and puts it in a row.

EXAMPLE

Claim Number | Total1 | Total2 |Total3 | Description | Code 1 | Numbers | Percentage

Any ideas would be great?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Will the claim numbers always be represented on all 3 tabs (i.e. is there a time when a claim number appears on one tab but not the other 2 or some other scenario)?
 
Upvote 0
Will the claim numbers always be represented on all 3 tabs (i.e. is there a time when a claim number appears on one tab but not the other 2 or some other scenario)?

Yes there may be a time when the claim number appears only one tab and not the other 2 or other scenario like this
 
Upvote 0
Give this a try. It assumes your headers are always in row 1 on all 4 tabs.

Code:
Sub Process_Report()

Dim wkb As Workbook
Dim Sheet1 As Worksheet, Sheet2 As Worksheet, Sheet3 As Worksheet, Sheet4 As Worksheet
Dim Sheet1ClaimNumCol As Long, Sheet1Total1Col As Long, Sheet1Total2Col As Long, Sheet1Total3Col As Long, Sheet1LastRow As Long
Dim Sheet2ClaimNumCol As Long, Sheet2DescCol As Long, Sheet2Code1Col As Long, Sheet2LastRow As Long
Dim Sheet3ClaimNumCol As Long, Sheet3NumbersCol As Long, Sheet3PercentageCol As Long, Sheet3LastRow As Long
Dim Sheet4ClaimNumCol As Long, Sheet4Total1Col As Long, Sheet4Total2Col  As Long
Dim Sheet4Total3Col As Long, Sheet4DescCol As Long, Sheet4Code1Col As Long, Sheet4NumbersCol As Long
Dim Sheet4PercentageCol As Long, Sheet4LastRow As Long
Dim myClaim As Variant, myClaimCheck As Variant
Dim myTotal1 As Variant, myTotal2 As Variant, myTotal3 As Variant, myDesc As Variant
Dim myCode1 As Variant, myNumbers As Variant, myPercentage As Variant

Set wkb = ThisWorkbook
Set Sheet1 = wkb.Worksheets("Sheet1")
Set Sheet2 = wkb.Worksheets("Sheet2")
Set Sheet3 = wkb.Worksheets("Sheet3")
Set Sheet4 = wkb.Worksheets("Sheet4")

'=================================================================================================
'=============Define Variables=================================================================
    '======= Sheet1 ==================================
    With Sheet1.Rows(1)
    
        '.Select
        Sheet1ClaimNumCol = .Find(What:="Claim Number", SearchDirection:=xlPrevious, LookAt:=xlWhole, SearchOrder:=xlByColumns).Column
        Sheet1Total1Col = .Find(What:="Total1", SearchDirection:=xlPrevious, LookAt:=xlWhole, SearchOrder:=xlByColumns).Column
        Sheet1Total2Col = .Find(What:="Total2", SearchDirection:=xlPrevious, LookAt:=xlWhole, SearchOrder:=xlByColumns).Column
        Sheet1Total3Col = .Find(What:="Total3", SearchDirection:=xlPrevious, LookAt:=xlWhole, SearchOrder:=xlByColumns).Column
        Sheet1LastRow = .Cells(Rows.Count, Sheet1ClaimNumCol).End(xlUp).Row
        
    End With
    
    '======= Sheet2 ==================================
    With Sheet2.Rows(1)
    
        '.Select
        Sheet2ClaimNumCol = .Find(What:="Claim Number", SearchDirection:=xlPrevious, LookAt:=xlWhole, SearchOrder:=xlByColumns).Column
        Sheet2DescCol = .Find(What:="Description", SearchDirection:=xlPrevious, LookAt:=xlWhole, SearchOrder:=xlByColumns).Column
        Sheet2Code1Col = .Find(What:="Code 1", SearchDirection:=xlPrevious, LookAt:=xlWhole, SearchOrder:=xlByColumns).Column
        Sheet2LastRow = .Cells(Rows.Count, Sheet2ClaimNumCol).End(xlUp).Row
        
    End With
    
    '======= Sheet3 ==================================
    With Sheet3.Rows(1)
    
        '.Select
        Sheet3ClaimNumCol = .Find(What:="Claim Number", SearchDirection:=xlPrevious, LookAt:=xlWhole, SearchOrder:=xlByColumns).Column
        Sheet3NumbersCol = .Find(What:="Numbers", SearchDirection:=xlPrevious, LookAt:=xlWhole, SearchOrder:=xlByColumns).Column
        Sheet3PercentageCol = .Find(What:="Percentage", SearchDirection:=xlPrevious, LookAt:=xlWhole, SearchOrder:=xlByColumns).Column
        Sheet3LastRow = .Cells(Rows.Count, Sheet3ClaimNumCol).End(xlUp).Row
        
    End With
    
    '======= Sheet4 ==================================
    With Sheet4.Rows(1)
        
        Sheet4ClaimNumCol = .Find(What:="Claim Number", SearchDirection:=xlPrevious, LookAt:=xlWhole, SearchOrder:=xlByColumns).Column
        Sheet4Total1Col = .Find(What:="Total1", SearchDirection:=xlPrevious, LookAt:=xlWhole, SearchOrder:=xlByColumns).Column
        Sheet4Total2Col = .Find(What:="Total2", SearchDirection:=xlPrevious, LookAt:=xlWhole, SearchOrder:=xlByColumns).Column
        Sheet4Total3Col = .Find(What:="Total3", SearchDirection:=xlPrevious, LookAt:=xlWhole, SearchOrder:=xlByColumns).Column
        Sheet4DescCol = .Find(What:="Description", SearchDirection:=xlPrevious, LookAt:=xlWhole, SearchOrder:=xlByColumns).Column
        Sheet4Code1Col = .Find(What:="Code 1", SearchDirection:=xlPrevious, LookAt:=xlWhole, SearchOrder:=xlByColumns).Column
        Sheet4NumbersCol = .Find(What:="Numbers", SearchDirection:=xlPrevious, LookAt:=xlWhole, SearchOrder:=xlByColumns).Column
        Sheet4PercentageCol = .Find(What:="Percentage", SearchDirection:=xlPrevious, LookAt:=xlWhole, SearchOrder:=xlByColumns).Column
        Sheet4LastRow = .Cells(Rows.Count, Sheet4ClaimNumCol).End(xlUp).Row
        
    End With
    
    
    '========Determine unique list of claim numbers from all 3 tabs===========================
    With Sheet1
        .Select
        .Range(Cells(2, Sheet1ClaimNumCol), Cells(Sheet1LastRow, Sheet1ClaimNumCol)).Copy
    End With
    
    With Sheet4
        .Cells(Sheet4LastRow + 1, Sheet4ClaimNumCol).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Sheet4LastRow = .Cells(Rows.Count, Sheet4ClaimNumCol).End(xlUp).Row
    End With
    
    With Sheet2
        .Select
        .Range(Cells(2, Sheet2ClaimNumCol), Cells(Sheet2LastRow, Sheet2ClaimNumCol)).Copy
    End With
    
    With Sheet4
        .Select
        .Cells(Sheet4LastRow + 1, Sheet4ClaimNumCol).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Sheet4LastRow = .Cells(Rows.Count, Sheet4ClaimNumCol).End(xlUp).Row
    End With
    
    With Sheet3
        .Select
        .Range(Cells(2, Sheet3ClaimNumCol), Cells(Sheet3LastRow, Sheet3ClaimNumCol)).Copy
    End With
    
    With Sheet4
        .Select
        .Cells(Sheet4LastRow + 1, Sheet4ClaimNumCol).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Sheet4LastRow = .Cells(Rows.Count, Sheet4ClaimNumCol).End(xlUp).Row
    End With
    
    With Sheet4
        .Columns("A:A").RemoveDuplicates Columns:=Sheet4ClaimNumCol, Header:=xlYes
    End With
    
    '============Loop through each sheet, set values on 4th sheet ==============================
    For i = 2 To Sheet4LastRow
        
        myClaim = Sheet4.Cells(i, Sheet4ClaimNumCol).Value
        myTotal1 = ""
        myTotal2 = ""
        myTotal3 = ""
        myDesc = ""
        myCode1 = ""
        myNumbers = ""
        myPercentage = ""
    
        With Sheet1
        
            For j = 2 To Sheet1LastRow
            
                myClaimCheck = .Cells(j, Sheet1ClaimNumCol).Value
                
                If myClaim = myClaimCheck Then
                    myTotal1 = .Cells(j, Sheet1Total1Col).Value
                    myTotal2 = .Cells(j, Sheet1Total2Col).Value
                    myTotal3 = .Cells(j, Sheet1Total3Col).Value
                End If
            
            Next j
        
        End With
        
        With Sheet2
        
            For k = 2 To Sheet2LastRow
            
                myClaimCheck = .Cells(k, Sheet2ClaimNumCol).Value
                
                If myClaim = myClaimCheck Then
                    myDesc = .Cells(k, Sheet2DescCol).Value
                    myCode1 = .Cells(k, Sheet2Code1Col).Value
                End If
            
            Next k
        
        End With
        
        With Sheet3
        
            For l = 2 To Sheet3LastRow
            
                myClaimCheck = .Cells(l, Sheet3ClaimNumCol).Value
                
                If myClaim = myClaimCheck Then
                    myNumbers = .Cells(l, Sheet3NumbersCol).Value
                    myPercentage = .Cells(l, Sheet3PercentageCol).Value
                End If
            
            Next l
        
        End With
        
        With Sheet4
        
            Cells(i, Sheet4Total1Col) = myTotal1
            Cells(i, Sheet4Total2Col) = myTotal2
            Cells(i, Sheet4Total3Col) = myTotal3
            Cells(i, Sheet4DescCol) = myDesc
            Cells(i, Sheet4Code1Col) = myCode1
            Cells(i, Sheet4NumbersCol) = myNumbers
            Cells(i, Sheet4PercentageCol) = myPercentage
        End With
        
    Next i
            
End Sub
 
Upvote 0
Thanks Ryan - Slight change to my report but it is still the same but the headings have changed. I have tried to reproduce the script based on the new headings but failed.

1st Worksheet called 'TOTALS'

Headings in Row 1 - Columns A to G

'AccountNumber' 'CHARGE' 'PAYMENTS' 'REFUNDS' 'INTEREST' 'WRITEOFF' 'TRANSFER'

2nd Worksheet called 'COSTS'

Headings in Row 1 - Columns A to B

'AccountNumber' 'COSTS'

3rd Worksheet called 'RVDETAILS'

Headings in Row 1 - Columns A to C

'AccountNumber' 'PROPDES' 'RV'

Unique Identifier is AccountNumber

All results will appear on the Worksheet called 'RESULTS'

Thanks in advance for your help
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,508
Members
452,918
Latest member
Davion615

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top