With this code everything works fine with the exception of the blue fonts ; it stops the copy paste special when BancorpSouth starts with the loop.
Can someone help me please
Thanks
Can someone help me please
Thanks
Code:
Sub Feed_invoices_FULL_LONG_version() 'LONG version 5.17.15
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim mydata As String
Dim sPath As String
Dim sFileName As String
Dim sSheetName As String
Dim pSheetName As String
Dim sRange As String
Dim res As String
Dim lastrow As Long, lastcolumn As Long
'Declare Arrays
Dim arrWB() As Variant
Dim thisWB As Workbook
'Clear contents in Control file
Sheets("Control").Range("b4:d120, f4:h120,j4:j120").ClearContents
'Constant Path
sPath = "C:\VBA\Automating\"
'open Data file
Workbooks.Open "C:\VBA\Automating\Data.xlsm"
'Message;close all workbooks
MsgBox "Please make sure all forecast models are closed"
'In worksheet; forecast
sSheetName = "Forecast"
pSheetName = "Prior Forecast"
'message ; what column do you want to paste to ?
res = InputBox("What column do you wish to paste to")
'Array Models 1 thru 3
arrWB = Array("AFCU-automate.xlsx", "Alaska CU-automate.xlsx", "American Savings Bank-automate.xlsx", _
"Ameriprise-automate.xlsx", "AMEX-automate.xlsx", [COLOR=#a52a2a]"BancorpSouth-automate.xlsx"[/COLOR], "Bank Hapoalim-automate.xlsx", _
"Bank Leumi-automate.xlsx", "Bank of America-automate.xlsx", "Bank of China-automate.xlsx", "Bank of Stockton-automate.xlsx", _
"Bank of the West-automate.xlsx", "Bank United-automate.xlsx", "BB&T-automate.xlsx", "BECU-automate.xlsx", _
"Bell State Bank and Trust-automate.xlsx", "California CU-automate.xlsx", "Capital One-automate.xlsx", "Capitol Federal-automate.xlsx", _
"Central Pacific Bank-automate.xlsx", "Charles Schwab-automate.xlsx", "Citibank-automate.xlsx", "Citizens-automate.xlsx", "Coastal Federal-automate.xlsx", _
"Comerica-automate.xlsx", "Commerce-automate.xlsx", "Compass-automate.xlsx", "Delta Community CU-automate.xlsx", "Desert Schools-automate.xlsx", _
"Discover-automate.xlsx", "Eastern-automate.xlsx", "Edward Jones-automate.xlsx", "Fidelity Investments-automate.xlsx", "First Bank Data-automate.xlsx", _
"First Banks-automate.xlsx", "First Citizens-automate.xlsx", "First Niagara-automate.xlsx", "First Technology-automate.xlsx", "Flagstar-automate.xlsx", _
"FNB of PA-automate.xlsx", "Fulton Financial-automate.xlsx", "Golden One-automate.xlsx", "Goldman Sachs-automate.xlsx", "Green Dot-automate.xlsx", _
"HSBC-automate.xlsx", "ING-automate.xlsx", "Investors Bank-automate.xlsx", "JP Morgan Chase-automate.xlsx", "M&T-automate.xlsx", "Mellon-automate.xlsx", _
"Merrill Lynch-automate.xlsx", "Mission-automate.xlsx", "Morgan Stanley-automate.xlsx", "Mutual of Omaha-automate.xlsx", "National Penn-automate.xlsx", _
"Navy-automate.xlsx", "New York Community-automate.xlsx", "Northern Trust-automate.xlsx", "Old National-automate.xlsx", "OnPoint-automate.xlsx", _
"Pershing-automate.xlsx", "PNC-automate.xlsx", "Rabobank-automate.xlsx", "Randolph Brooks-automate.xlsx", "Raymond James-automate.xlsx", _
"RBC Georgia-automate.xlsx", "Regions Bank-automate.xlsx", "San Diego County CU-automate.xlsx", "Sandia Labs-automate.xlsx", "Santander-automate.xlsx", _
"Simple Bank-automate.xlsx", "Space Coast-automate.xlsx", "Stanford-automate.xlsx", "Suntrust-automate.xlsx", "Synovus-automate.xlsx", "TD Bank-automate.xlsx", _
"Technology CU-automate.xlsx", "Tri Counties Bank-automate.xlsx", "Umpqua-automate.xlsx", "Union Bank-automate.xlsx", "US Bank-automate.xlsx", _
"USAA-automate.xlsx", "Utah Community CU-automate.xlsx", "Wells Fargo-automate.xlsx")
'When loop thru Array, build up the full file name string
For wbI = LBound(arrWB) To UBound(arrWB)
'Build the Filename
sFileName = sPath & arrWB(wbI)
'open Model wbI
Set thisWB = Workbooks.Open(filename:=sFileName)
'copy sum of invoice (SAP)
[COLOR=#0000ff] thisWB.Sheets(sSheetName).Range("A1983:A1983").Copy[/COLOR]
[COLOR=#0000ff] thisWB.Sheets(sSheetName).Range(res & 1983).PasteSpecial xlPasteValues[/COLOR]
[COLOR=#0000ff] [/COLOR]
'Copy all automated metrics
[COLOR=#0000ff] thisWB.Sheets(sSheetName).Range("A1999:b2045").Copy[/COLOR]
[COLOR=#0000ff] thisWB.Sheets(sSheetName).Range(res & 1999).PasteSpecial xlPasteValues[/COLOR]
[COLOR=#0000ff] [/COLOR]
'COPY RESULTS TO CONTROL (the rows.count, 6 for example is for the sixth column on the control sheet)
ThisWorkbook.Sheets("Control").Cells(Rows.Count, 2).End(xlUp)(2).Value = thisWB.Sheets(sSheetName).Range("I10").Value
ThisWorkbook.Sheets("Control").Cells(Rows.Count, 3).End(xlUp)(2).Value = thisWB.Sheets(sSheetName).Range(res & 1993).Value
ThisWorkbook.Sheets("Control").Cells(Rows.Count, 4).End(xlUp)(2).Value = thisWB.Sheets(sSheetName).Range(res & 1989).Value
ThisWorkbook.Sheets("Control").Cells(Rows.Count, 7).End(xlUp)(2).Value = thisWB.Sheets(sSheetName).Range(res & 14).Offset(0, 1).Value
ThisWorkbook.Sheets("Control").Cells(Rows.Count, 8).End(xlUp)(2).Value = thisWB.Sheets(pSheetName).Range(res & 14).Offset(0, 1).Value
'Save and Close Model
thisWB.Saved = True
thisWB.Close
Next wbI
'Close the Data file without saving
Application.EnableEvents = False
Workbooks("Data.xlsm").Close SaveChanges:=False
MsgBox "Feed was completed!"
End Sub