Hey Jerry,
The code you posted for this last part is fine, the problem is the column and row vary from sheet to sheet, which is completely my fault for not making them uniform. That being said I tried to work around it by writing that code into the part where I copy the "Cumulative Share Avg." value in each sheet (because in that part I go sheet by sheet), but it gave me the "Run-Time Error '91': Object Variable or With Block Variable Not Set" error. I've copied the code below with the portion the debugger highlights in yellow text. I think this is because at this point in the code WSMain has not been defined, I'm just not sure how to fix it.....
Sub CopyValuesToMaster()
'
' CopyValuesToMaster Macro This macro copies all of the individual TR files to a master district file as values so it's editable without blowing up the sheet
'
'
Dim wbData As Workbook, wbMain As Workbook
Dim wsMain As Worksheet, wsData As Worksheet
Dim LR As Long, NR As Long
Dim fPath As String, fName As String
Set wbMain = ThisWorkbook
'if files are stored in separate directory edit fPath
fPath = ThisWorkbook.Path & "\" 'don't forget the final \
fName = Dir(fPath & "*.xlsx") 'start looping through files one at a time
Application.ScreenUpdating = False
Do While Len(fName) > 0
If fName <> ThisWorkbook.Name Then
Set wbData = Workbooks.Open(fPath & fName)
Sheets("Snuff").Select
Range("Q12").Select
ActiveCell.FormulaR1C1 = "=R8C13"
Range("Q12").Select
Selection.AutoFill Destination:=Range("Q12:Q1000"), Type:=xlFillDefault
Range("Q12:Q1000").Select
With ActiveSheet
.UsedRange.Copy
.UsedRange.PasteSpecial xlPasteValues
.Rows(11).AutoFilter
.Rows(11).AutoFilter Field:=12, Criteria1:="<=0.8"
LR = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("A11:A" & LR).EntireRow.Copy
wsMain.Range("A" & NR).PasteSpecial xlPasteValuesAndNumberFormats
.AutoFilterMode = False
End With
Sheets("Cigars").Select
Range("Q12").Select
ActiveCell.FormulaR1C1 = "=R8C11"
Range("Q12").Select
Selection.AutoFill Destination:=Range("Q12:Q1000"), Type:=xlFillDefault
Range("Q12:Q1000").Select
With ActiveSheet
.UsedRange.Copy
.UsedRange.PasteSpecial xlPasteValues
.Rows(11).AutoFilter
.Rows(11).AutoFilter Field:=12, Criteria1:="<=0.8"
LR = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("A11:A" & LR).EntireRow.Copy
wsMain.Range("A" & NR).PasteSpecial xlPasteValuesAndNumberFormats
.AutoFilterMode = False
End With
Sheets("LL").Select
Range("K12").Select
ActiveCell.FormulaR1C1 = "=R8C7"
Range("K12").Select
Selection.AutoFill Destination:=Range("K12:K1000"), Type:=xlFillDefault
Range("K12:K1000").Select
With ActiveSheet
.UsedRange.Copy
.UsedRange.PasteSpecial xlPasteValues
.Rows(11).AutoFilter
.Rows(11).AutoFilter Field:=6, Criteria1:="<=0.8"
LR = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("A11:A" & LR).EntireRow.Copy
wsMain.Range("A" & NR).PasteSpecial xlPasteValuesAndNumberFormats
.AutoFilterMode = False
End With
Sheets("Snus").Select
Range("K12").Select
ActiveCell.FormulaR1C1 = "=R8C7"
Range("K12").Select
Selection.AutoFill Destination:=Range("K12:K1000"), Type:=xlFillDefault
Range("K12:K1000").Select
With ActiveSheet
.UsedRange.Copy
.UsedRange.PasteSpecial xlPasteValues
.Rows(11).AutoFilter
.Rows(11).AutoFilter Field:=6, Criteria1:="<=0.8"
LR = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("A11:A" & LR).EntireRow.Copy
wsMain.Range("A" & NR).PasteSpecial xlPasteValuesAndNumberFormats
.AutoFilterMode = False
End With
Sheets("Overall ($)").Select
Range("T11").Select
ActiveCell.FormulaR1C1 = "=R8C7"
Range("T11").Select
Selection.AutoFill Destination:=Range("T11:T1000"), Type:=xlFillDefault
Range("T11:T1000").Select
With ActiveSheet
.UsedRange.Copy
.UsedRange.PasteSpecial xlPasteValues
.Rows(10).AutoFilter
.Rows(10).AutoFilter Field:=14, Criteria1:="<=0.8"
LR = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("A10:A" & LR).EntireRow.Copy
wsMain.Range("A" & NR).PasteSpecial xlPasteValuesAndNumberFormats
.AutoFilterMode = False
End With
For Each wsData In wbData.Worksheets
Set wsMain = wbMain.Sheets(wsData.Name)
NR = wsMain.Range("A" & Rows.Count).End(xlUp).Row + 1
With wsData
LR = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("A11:A" & LR).EntireRow.Copy
wsMain.Range("A" & NR).PasteSpecial xlPasteValuesAndNumberFormats
.UsedRange.Copy
.UsedRange.PasteSpecial xlPasteValues
End With
Next wsData
fName = Left(fName, InStrRev(fName, ".") - 1) & "1.xlsx"
wbData.SaveAs fPath & "Values\" & fName, FileFormat:=51
wbData.Close False
End If
fName = Dir 'queue up next filename
Loop
Application.ScreenUpdating = True
End Sub
Bookmarks