Below is the far too complex code I haven't whittled down yet. I have a routine that performs a copy-past from one workbook to a compiled workbook. Sometimes the source data is bad (ie, the source workbook thinks that 9 contiguous cells are non=contiguous BS error) When an error like this occurs, I want to be able to capture the WB name that popped the error then skip that workbook and continue. At the end I would like a Pop up of errored out WBs. Can this be done give what I have?
Due to the sensitivity of the data, I cannot accurately recreate of share the files. The repetition for Risk A/B/C is due to the risk groups being contiguous in rows, but the same 5 categories...its a mess and i a trying to untagle it.
Private Sub DoSomething(ByRef wb As Workbook, ByVal CurrentRow As Long)
Dim copyRiskAFrom As Range
Dim copyRiskATo As Range
Dim copyRiskBFrom As Range
Dim copyRiskBTo As Range
Dim copyRiskCFrom As Range
Dim copyRiskCTo As Range
Dim copyBaseDataFrom As Range
Dim copyBaseDataTo As Range
Dim wb2 As Workbook
Dim ancHosp As Range
Dim lrow As Long
Dim lcell1 As Long
Dim lcell2 As Long
Dim riskA As Range
Dim lcellA As Long
Dim lcellA2 As Long
Dim lrowA As Long
Dim riskB As Range
Dim lcellB As Long
Dim lcellB2 As Long
Dim lrowB As Long
Dim riskC As Range
Dim lcellC As Long
Dim lcellC2 As Long
Dim lrowC As Long
Dim TestWorkbook As Workbook
Dim wsCheck As Worksheet
Dim i As Integer
'test to see if the destination workbook is already open
' Set TestWorkbook = Nothing
' On Error Resume Next
' Set TestWorkbook = Workbooks("Targets09.30.14V1 - Copy.xlsx")
' On Error GoTo 0
'
' If TestWorkbook Is Nothing Then
' MsgBox "Please open the destination file, 'Targets09.30.14V1 - Copy.xlsx'."
' Exit Sub
' End If
Workbooks.Open ("H:\Shared\DataGen\DG Group\Bundled Payments\Temporary John Folder\New folder\Targets09.30.14V1 - Copy.xlsx")
Set wb2 = Workbooks("Targets09.30.14V1 - Copy.xlsx")
Set wsCheck = wb.Worksheets(2)
i = 2
step1:
'******************************Risk A***********************************
'***********************Copy Base Data columns (Clinical Episode, MSDRG and N)
'set the copy range
With wsCheck
Set copyBaseDataFrom = .Range(.Range("A5"), .Range("C5").End(xlDown))
End With
'set where we are copying to
Set copyBaseDataTo = wb2.Worksheets(2).Range("C" & Rows.count).End(xlUp).Offset(1, 0)
'perform the copy/paste without the borders
copyBaseDataFrom.Copy
copyBaseDataTo.PasteSpecial Paste:=xlPasteAllExceptBorders
Application.CutCopyMode = False
'************************** set copy/Paste Range for Risk A
'set the copy range
With wsCheck
Set copyRiskAFrom = .Range(.Range("D5"), .Range("H5").End(xlDown))
End With
'set where we are copying to
Set copyRiskATo = wb2.Worksheets(2).Range("F" & Rows.count).End(xlUp).Offset(1, 0)
'perform the copy/paste without the borders
copyRiskAFrom.Copy
copyRiskATo.PasteSpecial Paste:=xlPasteAllExceptBorders
Application.CutCopyMode = False
'************************************** Risk A Definition
'capture the Risk Definition
With wsCheck
Set riskA = .Range("D3")
End With
'determine the last full cell in Column K and start in the next one down
With wb2.Worksheets(2)
lcellA = .Range("K" & Rows.count).End(xlUp).Offset(1).row
End With
'copy the Risk Definition name to the first empty cell in column K
riskA.Copy Destination:=wb2.Worksheets(2).Range("K" & lcellA)
'autofill the Risk definition from the first cell its in, down the the last row with data in column C
With wb2.Worksheets(2)
lcellA2 = .Range("K" & Rows.count).End(xlUp).row
lrowA = .Range("C" & Rows.count).End(xlUp).row
.Range("K" & lcellA2 & ":K" & lrowA).FillDown
End With
'****************************Risk B*********************************************
'***********************Copy Base Data columns (Clinical Episode, MSDRG and N)
'set the copy range
With wsCheck
Set copyBaseDataFrom = .Range(.Range("A5"), .Range("C5").End(xlDown))
End With
'set where we are copying to
Set copyBaseDataTo = wb2.Worksheets(2).Range("C" & Rows.count).End(xlUp).Offset(1, 0)
'perform the copy/paste without the borders
copyBaseDataFrom.Copy
copyBaseDataTo.PasteSpecial Paste:=xlPasteAllExceptBorders
Application.CutCopyMode = False
'************************** set copy/Paste Range for Risk B
'set the copy range
With wsCheck
Set copyRiskBFrom = .Range(.Range("I5"), .Range("M5").End(xlDown))
End With
'set where we are copying to
Set copyRiskBTo = wb2.Worksheets(2).Range("F" & Rows.count).End(xlUp).Offset(1, 0)
'perform the copy/paste without the borders
copyRiskBFrom.Copy
copyRiskBTo.PasteSpecial Paste:=xlPasteAllExceptBorders
Application.CutCopyMode = False
'************************************** Risk B Definition
'capture the Risk Definition
With wsCheck
Set riskB = .Range("I3")
End With
'determine the last full cell in Column K and start in the next one down
With wb2.Worksheets(2)
lcellB = .Range("K" & Rows.count).End(xlUp).Offset(1).row
End With
'copy the Risk Definition name to the first empty cell in column K
riskB.Copy Destination:=wb2.Worksheets(2).Range("K" & lcellB)
'autofill the Risk definition from the first cell its in, down the the last row with data in column C
With wb2.Worksheets(2)
lcellB2 = .Range("K" & Rows.count).End(xlUp).row
lrowB = .Range("C" & Rows.count).End(xlUp).row
.Range("K" & lcellB2 & ":K" & lrowB).FillDown
End With
'****************************Risk C*********************************************
'***********************Copy Base Data columns (Clinical Episode, MSDRG and N)
'set the copy range
With wsCheck
Set copyBaseDataFrom = .Range(.Range("A5"), .Range("C5").End(xlDown))
End With
'set where we are copying to
Set copyBaseDataTo = wb2.Worksheets(2).Range("C" & Rows.count).End(xlUp).Offset(1, 0)
'perform the copy/paste without the borders
copyBaseDataFrom.Copy
copyBaseDataTo.PasteSpecial Paste:=xlPasteAllExceptBorders
Application.CutCopyMode = False
'************************** set copy/Paste Range for Risk B
'set the copy range
With wsCheck
Set copyRiskCFrom = .Range(.Range("N5"), .Range("R5").End(xlDown))
End With
'set where we are copying to
Set copyRiskCTo = wb2.Worksheets(2).Range("F" & Rows.count).End(xlUp).Offset(1, 0)
'perform the copy/paste without the borders
copyRiskCFrom.Copy
copyRiskCTo.PasteSpecial Paste:=xlPasteAllExceptBorders
Application.CutCopyMode = False
'************************************** Risk B Definition
'capture the Risk Definition
With wsCheck
Set riskC = .Range("N3")
End With
'determine the last full cell in Column K and start in the next one down
With wb2.Worksheets(2)
lcellC = .Range("K" & Rows.count).End(xlUp).Offset(1).row
End With
'copy the Risk Definition name to the first empty cell in column K
riskC.Copy Destination:=wb2.Worksheets(2).Range("K" & lcellC)
'autofill the Risk definition from the first cell its in, down the the last row with data in column C
With wb2.Worksheets(2)
lcellC2 = .Range("K" & Rows.count).End(xlUp).row
lrowC = .Range("C" & Rows.count).End(xlUp).row
.Range("K" & lcellC2 & ":K" & lrowC).FillDown
End With
'***********************************************************************************
'******************************** Anchor Hosp Name
'capture the Anchor Hopsital's name
With wb.Worksheets(1)
Set ancHosp = .Range("A3")
End With
'determine the last full cell in Column A and start in the next one down
With wb2.Worksheets(2)
lcell1 = .Range("A" & Rows.count).End(xlUp).Offset(1).row
End With
'copy the Anchor hospital name to the first empty cell in column A
ancHosp.Copy Destination:=wb2.Worksheets(2).Range("A" & lcell1)
'autofill the Anchor hospital name from the first cell its in, down the the last row with data in column C
With wb2.Worksheets(2)
lcell2 = .Range("A" & Rows.count).End(xlUp).row
lrow = .Range("C" & Rows.count).End(xlUp).row
.Range("A" & lcell2 & ":A" & lrow).FillDown
End With
If i = wb.Worksheets.count Then
MsgBox "Workbook Complete."
Exit Sub
ElseIf i <> wb.Worksheets.count Then
i = i + 2
Set wsCheck = wb.Worksheets(i)
GoTo step1
End Sub
Bookmarks