cliniconboarding
New Member
- Joined
- Mar 3, 2018
- Messages
- 7
[FONT="]I currently use the below code to split data by provider last name, from a list of quality metrics that are due.[/FONT]
[FONT="]
[/FONT]
[FONT="]This is a multistep process to trim the csv file I receive with 60 columns of data and a variable number of rows, down to the 9 columns of data that I have sorted by what is actually due, split by each provider onto a worksheet named "Their last name". That process is now perfected (Thanks to Fluff on a recent post).[/FONT]
[FONT="]
[/FONT]
[FONT="]
[/FONT]
[FONT="]Now I'm just tidying up however and I’m left with 5 separate workbooks, one for each quality metric and currently I’ll have to print them all, sort, and staple per provider (Not the end of the world). Though, I'd love to save some paper and time and merge them together.
Given this,
There are two things I'm bumping into:[/FONT]
[/FONT]
[FONT="] I've created a master with every possible name (about 50), and tried to run the following code referencing a source file where everything was placed together: I received no errors and I got my little message box, yet nothing happened. My preference would be that it simply reference whatever Excel documents were open and pulled them into the active workbook. Including the header from their respective sheet (to identify which metric it references) into the next available line. Not sure if I should be trying to do something with vblookup here? Any guidance is appreciated, ya'll are like textbooks of knowledge!
[/FONT]
S
[FONT="]
[/FONT]
[FONT="]This is a multistep process to trim the csv file I receive with 60 columns of data and a variable number of rows, down to the 9 columns of data that I have sorted by what is actually due, split by each provider onto a worksheet named "Their last name". That process is now perfected (Thanks to Fluff on a recent post).[/FONT]
Code:
Sub parse_NonPCProviders()
Dim lr As Long
Dim ws As Worksheet
Dim vcol, i As Integer
Dim icol As Long
Dim myarr As Variant
Dim title As String
Dim titlerow As Integer
MsgBox (" Brace yourself for this one. You may need to walk away for a bit. ")
vcol = 4
Set ws = Sheets("ADD")
lr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row
title = "A1:H1"
titlerow = ws.Range(title).Cells(1).Row
icol = ws.Columns.Count
ws.Cells(1, icol) = "Unique"
For i = 2 To lr
On Error Resume Next
If ws.Cells(i, vcol) <> "" And Application.WorksheetFunction.Match(ws.Cells(i, vcol), ws.Columns(icol), 0) = 0 Then
ws.Cells(ws.Rows.Count, icol).End(xlUp).Offset(1) = ws.Cells(i, vcol)
End If
Next
myarr = Application.WorksheetFunction.Transpose(ws.Columns(icol).SpecialCells(xlCellTypeConstants))
ws.Columns(icol).Clear
For i = 2 To UBound(myarr)
ws.Range(title).AutoFilter field:=vcol, Criteria1:=myarr(i) & ""
If Not Evaluate("=ISREF('" & myarr(i) & "'!A1)") Then
Sheets.Add(after:=Worksheets(Worksheets.Count)).Name = myarr(i) & ""
Else
Sheets(myarr(i) & "").Move after:=Worksheets(Worksheets.Count)
End If
ws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(myarr(i) & "").Range("A" & Rows.Count).End(xlUp).Offset(1)
Sheets(myarr(i) & "").Columns.AutoFit
Next
ws.AutoFilterMode = False
ws.Activate
MsgBox (" Yeah, you thought it was going to crash didn't you? ")
End Sub
[/FONT]
[FONT="]
[/FONT]
[FONT="]Now I'm just tidying up however and I’m left with 5 separate workbooks, one for each quality metric and currently I’ll have to print them all, sort, and staple per provider (Not the end of the world). Though, I'd love to save some paper and time and merge them together.
Given this,
There are two things I'm bumping into:[/FONT]
- Since the quality metrics differ, the header in one column is different on each workbook (with the name of the metric numerator).
- The names on the sheets might not be the same.
- What I mean by this, is that out of our providers we have say: Amy, Bob, Charlie, Dave, Evan
- But on one metric only Amy, Bob, Charlie had anything due. So they’re the only ones with worksheets.
- And on another everyone has something due.
- On another it might only be Bob, Dave, Evan
- What I mean by this, is that out of our providers we have say: Amy, Bob, Charlie, Dave, Evan
[/FONT]
[FONT="] I've created a master with every possible name (about 50), and tried to run the following code referencing a source file where everything was placed together: I received no errors and I got my little message box, yet nothing happened. My preference would be that it simply reference whatever Excel documents were open and pulled them into the active workbook. Including the header from their respective sheet (to identify which metric it references) into the next available line. Not sure if I should be trying to do something with vblookup here? Any guidance is appreciated, ya'll are like textbooks of knowledge!
[/FONT]
S
Code:
ub Copy_From_All_Workbooks()
Dim wb As String, i As Long, sh As Worksheet
Application.ScreenUpdating = False
wb = Dir(ThisWorkbook.Path & "\*")
Do Until wb = ""
If wb <> ThisWorkbook.Name Then
Workbooks.Open ThisWorkbook.Path & "\*" & wb
For Each sh In Workbooks(wb).Worksheets
sh.UsedRange.Copy '<---- Assumes all header rows
ThisWorkbook.Sheets(sh.Name).Cells(Rows.Count, 1).End(xlUp).Offset(1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Next sh
Workbooks(wb).Close False
End If
wb = Dir
Loop
Application.ScreenUpdating = True
MsgBox "All worksheets have been copied successfully"
End Sub