error generated in complete code but when run on its own.

Afro_Cookie

Board Regular
Joined
Mar 17, 2020
Messages
103
Office Version
  1. 365
Platform
  1. Windows
I'm in the final stages of this and I could use some help.

There is a bug that is causing merged cells to unmerge and shifting my data on my 'Filtered' sheet, which I don't understand as the piece of code isn't interacting with that sheet. I tried running the piece of code on its own and there were no errors.

error generated at this point when entire code is run
VBA Code:
'copying the 'QC info' data from 'yesterday' to 'today'
Sheets("Yesterday").Range("Table1[QC Notes]").Copy Sheets("Today").Range("I2")

M file consists of three sheets, that may need to be duplicated, that I'll post below the completed code.

VBA Code:
Sub ColourMeElmo()

Application.ScreenUpdating = False

'establish the criteria for colouring cells
Dim i As Long, r1 As Range, r2 As Range

'code for selecting which cells get coloured backgrounds
Sheets("Filter").Select
On Error Resume Next
For i = 6 To 150
Set r1 = Range("B" & i)
Set r2 = Range("L" & i & ":S" & i)
If r1.Value = "" Then r2.Interior.Color = vbYellow
 Next i

' For "Today" data that gets copied, pasted into the 'Today' sheet from 'Filter', after formatting has taken place
ActiveSheet.Range("L6", ActiveSheet.Range("L6").End(xlDown).End(xlToRight)).Copy
Sheets("Today").Range("K2").PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Sheets("Today").Range("K2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
          
' For "Yesterday" data that gets copied, pasted into the 'yesterday' sheet from 'fileter', after formatting has taken place
Sheets("Filter").Range("B6", ActiveSheet.Range("B6").End(xlDown).End(xlToRight)).Copy
Sheets("Yesterday").Range("A2").PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Sheets("Yesterday").Range("A2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

'overrighting current table data with the newly filtered data
Sheets("Today").Range("K2").CurrentRegion.Offset(1, 0).Cut Range("A2")

'copying the 'QC info' data from 'yesterday' to 'today'
Sheets("Yesterday").Range("Table1[QC Notes]").Copy Sheets("Today").Range("I2")
        
'Deleting blank rows in table
ActiveSheet.ListObjects("Table2").Range.AutoFilter Field:=1, Criteria1:="="
ActiveSheet.AutoFilter.Range.Offset(1).Delete
ActiveSheet.ListObjects("Table2").Range.AutoFilter Field:=1

'delete all rows from 'Yesterday' table
Sheets("Yesterday").Select
If Not ActiveCell.ListObject Is Nothing Then
ActiveCell.ListObject.DataBodyRange.Delete
End If
        
'transfer data from 'Today' to 'Yesterday'
Sheets("Today").Range("A1").CurrentRegion.Offset(1, 0).Cut Sheets("Yesterday").Range("A2")

'reset sheets
Sheets("Today").Columns("J:S").EntireColumn.Delete
Sheets("Filter").Range("A:T").Interior.Color = xlNone
    
'go to main sheet
Sheets("Yesterday").Range("A2").Select
    
Application.ScreenUpdating = True

End Sub

Sheet 1 "Yesterday"
Sheet 2 "Today"
Sheet 3 "Filter"

Sheet 1
logistics shipping playground.xlsm
ABCDEFGHI
1PARTDESCRIPTIONUNITPLANARTICLEQOHBOL SHIP QTYSERIAL COUNTQC Notes
2JAR04888011PCa26140410601
3JAR04897012PCa2618076725202
4JAR05330013PCa2622698443201
5JAR05378014PCa2623449418001
6JAR05409015PCa2618216251602
7JAR05620016PCa2615455849802
8JAR05835017PCa2638566713201
9JAR05840018PCa263851895401
10JAR05847019PCa263839874201
11JAR058840110PCa263905584518012
12JAR059170111PCa2638830952802
13JAR059400112PCa264385634201
14JAR059450113PCa26410259230642306450
15JAR059610114PCa264108656426423
16JAR059630115PCa2641027852202
17JAR059810116PCa2619183239601
18JAR059900117PCa264807875316531614
19JAR059980118PCa26459578259202064054
20JAR059990119PCa264595865922021120134
21JAR060000120PCa26426981129921299216
22JAR060010121PCa26426978718474888
23JAR060030122PCa26426982141761417616
24JAR060110123PCa264373866886884
25JAR060170124PCa26438505294322943237
26JAR060250125PCa2644160912144078720263
27JAR060270126PCa26441613478440120
28JAR060290127PCa2644161210470084000229
29JAR060310128PCa2644162410887682368228
30JAR060400129PCa264398485011850184105
31JAR060410130PCa2643940044298093FP burn - started 1/2/22
32JAR060440131PCa2644874314792016
33JAR060460132PCa264398485157631896108
34JAR060500133PCa26448735710408
35JAR060540134PCa26448733467844305651
36JAR060700135PCa2644874054768064
Yesterday


Sheet 2
logistics shipping playground.xlsm
ABCDEFGHI
1PARTDESCRIPTIONUNITPLANARTICLEQOHBOL SHIP QTYSERIAL COUNTQC Notes
2JAR04888011PCa26140410601
3JAR04897012PCa2618076725202
4JAR05330013PCa2622698443201
5JAR05378014PCa2623449418001
6JAR05409015PCa2618216251602
7JAR05620016PCa2615455849802
8JAR05835017PCa2638566713201
9JAR05840018PCa263851895401
10JAR05847019PCa263839874201
11JAR058840110PCa263905584518012
12JAR059170111PCa2638830952802
13JAR059400112PCa264385634201
14JAR059450113PCa26410259153601536033
15JAR059630114PCa2641027852202
16JAR059810115PCa2619183239601
17JAR059900116PCa26480787288028806
18JAR059980117PCa26459578225602256047
19JAR059990118PCa264595867204852800151
20JAR060000119PCa26426981129921299216
21JAR060010120PCa26426978718474888
22JAR060030121PCa26426982141761417616
23JAR060110122PCa264373866886884
24JAR060170123PCa26438505290162901636
25JAR060250124PCa2644160910282887360215
26JAR060270125PCa2644161310240847040215
27JAR060290126PCa264416127489267680157
28JAR060310127PCa264416247594875840159
29JAR060400128PCa26439848328383283869
30JAR060410129PCa2643940044298093
31JAR060440130PCa26448743147921479216
32JAR060460131PCa264398485157651162108
33JAR060500132PCa26448735710471048
34JAR060540133PCa26448733411684116845
35JAR060700134PCa26448740724085428878
Today


Sheet 3
logistics shipping playground.xlsm
ABCDEFGHIJKLMNOPQRST
5YesterdayToday
6JAR0488801JAR04888011PCa261404106010JAR04888011PCa261404106010
7JAR0489701JAR04897012PCa26180767252020JAR04897012PCa26180767252020
8JAR0533001JAR05330013PCa26226984432010JAR05330013PCa26226984432010
9JAR0537801JAR05378014PCa26234494180010JAR05378014PCa26234494180010
10JAR0540901JAR05409015PCa26182162516020JAR05409015PCa26182162516020
11JAR0562001JAR05620016PCa26154558498020JAR05620016PCa26154558498020
12JAR0583501JAR05835017PCa26385667132010JAR05835017PCa26385667132010
13JAR0584001JAR05840018PCa2638518954010JAR05840018PCa2638518954010
14JAR0584701JAR05847019PCa2638398742010JAR05847019PCa2638398742010
15JAR0588401JAR058840110PCa2639055845180120JAR058840110PCa2639055845180120
16JAR0591701JAR059170111PCa26388309528020JAR059170111PCa26388309528020
17JAR0594001JAR059400112PCa2643856342010JAR059400112PCa2643856342010
18JAR0594501JAR059450113PCa264102592306423064500JAR059450113PCa264102591536015360330
19JAR0596301JAR059630115PCa26410278522020JAR059630114PCa26410278522020
20JAR0598101JAR059810116PCa26191832396010JAR059810115PCa26191832396010
21JAR0599001JAR059900117PCa2648078753165316140JAR059900116PCa264807872880288060
22JAR0599801JAR059980118PCa264595782592020640540JAR059980117PCa264595782256022560470
23JAR0599901JAR059990119PCa2645958659220211201340JAR059990118PCa2645958672048528001510
24JAR0600001JAR060000120PCa264269811299212992160JAR060000119PCa264269811299212992160
25JAR0600101JAR060010121PCa264269787184748880JAR060010120PCa264269787184748880
26JAR0600301JAR060030122PCa264269821417614176160JAR060030121PCa264269821417614176160
27JAR0601101JAR060110123PCa2643738668868840JAR060110122PCa2643738668868840
28JAR0601701JAR060170124PCa264385052943229432370JAR060170123PCa264385052901629016360
29JAR0602501JAR060250125PCa264416091E+05787202630JAR060250124PCa26441609102828873602150
30JAR0602701JAR060270126PCa264416134784401200JAR060270125PCa26441613102408470402150
31JAR0602901JAR060290127PCa264416121E+05840002290JAR060290126PCa2644161274892676801570
32JAR0603101JAR060310128PCa264416241E+05823682280JAR060310127PCa2644162475948758401590
33JAR0604001JAR060400129PCa2643984850118501841050JAR060400128PCa264398483283832838690
34JAR0604101JAR060410130PCa2643940044298093FP burn - started 1/2/22JAR060410129PCa26439400442980930
35JAR0604401JAR060440131PCa26448743147920160JAR060440130PCa264487431479214792160
36JAR0604601JAR060460132PCa2643984851576318961080JAR060460131PCa2643984851576511621080
37JAR0605001JAR060500133PCa264487357104080JAR060500132PCa264487357104710480
38JAR0605401JAR060540134PCa264487334678443056510JAR060540133PCa264487334116841168450
39JAR0607001JAR060700135PCa26448740547680640JAR060700134PCa264487407240854288780
Filter
Cell Formulas
RangeFormula
A6:A40A6=SORT(UNIQUE(LET(r,ROWS(Table1),s,SEQUENCE(r+ROWS(Table2)),IFERROR(INDEX(#REF!,s),INDEX(Table2[PART],s-r)))))
B6:J39B6=FILTER(Table1,Table1[PART]=$A6,"")
L6:T39L6=FILTER(Table2,Table2[PART]=$A6,"")
Dynamic array formulas.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
There is a bug that is causing merged cells to unmerge and shifting my data on my 'Filtered' sheet, which I don't understand as the piece of code isn't interacting with that sheet. I tried running the piece of code on its own and there were no errors.

error generated at this point when entire code is run
VBA Code:
'copying the 'QC info' data from 'yesterday' to 'today'
Sheets("Yesterday").Range("Table1[QC Notes]").Copy Sheets("Today").Range("I2")
The error is not on the line you are indicacting but the line prior to that shown below and
that line is in fact interacting with the Filter sheet.

Especially when you are dealing with mulitple sheets it is preferable not to rely on a sheet being the ActiveSheet and specifying your references.

The below line looks to be Back to front. Presumably you are intending to copy from the Filter sheet to the Today sheet.
Range("A2") refers to the ActiveSheet which at this point is the Filter sheet. So if you didn't want to set variables for the sheets it would be better if you used Sheets("Filter").Range("A2").
It still looks back to front to me. The syntax is RangeFROM.Cut RangeTO

VBA Code:
    'overrighting current table data with the newly filtered data  <---- XXX I think you meant Overwriting XXX
    Sheets("Today").Range("K2").CurrentRegion.Offset(1, 0).Cut Range("A2")
 
Upvote 0
Solution
The error is not on the line you are indicacting but the line prior to that shown below and
that line is in fact interacting with the Filter sheet.

Especially when you are dealing with mulitple sheets it is preferable not to rely on a sheet being the ActiveSheet and specifying your references.

The below line looks to be Back to front. Presumably you are intending to copy from the Filter sheet to the Today sheet.
Range("A2") refers to the ActiveSheet which at this point is the Filter sheet. So if you didn't want to set variables for the sheets it would be better if you used Sheets("Filter").Range("A2").
It still looks back to front to me. The syntax is RangeFROM.Cut RangeTO

VBA Code:
    'overrighting current table data with the newly filtered data  <---- XXX I think you meant Overwriting XXX
    Sheets("Today").Range("K2").CurrentRegion.Offset(1, 0).Cut Range("A2")
thanks for the typo correction. You're right about the active sheet reference. I modified the code to show the sheet I wanted the data to paste to and it corrected itself.

VBA Code:
    'old code that generated the error
    Sheets("Today").Range("K2").CurrentRegion.Offset(1, 0).Cut Range("A2")
    
   'modified code to eliminate error
    Sheets("Today").Range("K2").CurrentRegion.Offset(1, 0).Cut Sheet("Today").Range("A2")
 
Upvote 0
Thanks for the update. Is it doing what it is supposed to now ?
After I specified the specific sheet I wanted to copy to, it is. Below is the final, updated code that works without a hitch. I know it's not the prities, but it works well for my current needs. If anyone reading this has ideas on how to streamline it further, I'm all eyes.

VBA Code:
Sub ColourMeElmo()

Application.ScreenUpdating = False

'establish the criteria for colouring cells
Dim i As Long, r1 As Range, r2 As Range

'code for selecting which cells get coloured backgrounds
   Sheets("Filter").Select
   On Error Resume Next
   For i = 6 To 41
      Set r1 = Range("B" & i)
      Set r2 = Range("L" & i & ":S" & i)
      If r1.Value = "" Then r2.Interior.Color = vbYellow
   Next i

' For "Receive" data that gets copied, pasted into the 'Receive' sheet from 'Filter', after formatting has taken place
    ActiveSheet.Range("L6", ActiveSheet.Range("L6").End(xlDown).End(xlToRight)).Copy
    Sheets("Receive").Range("K2").PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Sheets("Receive").Range("K2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
          
' For "Send" data that gets copied, pasted into the 'Send' sheet from 'fileter', after formatting has taken place
    Sheets("Filter").Range("B6", ActiveSheet.Range("B6").End(xlDown).End(xlToRight)).Copy
    Sheets("Send").Range("A2").PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Sheets("Send").Range("A2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

'overwrighting current table data with the newly filtered data
    Sheets("Receive").Range("K2").CurrentRegion.Cut Sheets("Receive").Range("A2")

'copying the 'QC info' data from 'Send' to 'Receive'
    Sheets("Send").Range("Table1[QC Notes]").Copy Sheets("Receive").Range("I2")
        
'Deleting blank rows in table
    Sheets("Receive").Select
    ActiveSheet.ListObjects("Table2").Range.AutoFilter Field:=1, Criteria1:="="
    ActiveSheet.AutoFilter.Range.Offset(1).Delete
    ActiveSheet.ListObjects("Table2").Range.AutoFilter Field:=1

'delete all rows from 'Send' table
    Sheets("Send").Select
        If Not ActiveCell.ListObject Is Nothing Then
            ActiveCell.ListObject.DataBodyRange.Delete
        End If
        
'transfer data from 'Receive' to 'Send'
    Sheets("Receive").Range("A2").CurrentRegion.Offset(1, 0).Copy
    Sheets("Send").Range("A2").PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Sheets("Send").Range("A2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    
'reset sheets
    Sheets("Send").Columns("J:S").EntireColumn.Delete
    Sheets("Filter").Range("A:T").Interior.Color = xlNone
        
'delete all rows from 'Receive' table
    Sheets("Receive").Select
    Range("A2").Select
        If Not ActiveCell.ListObject Is Nothing Then
            ActiveCell.ListObject.DataBodyRange.Delete
        End If
        
'go to main sheet
    Sheets("Send").Select
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:="="
    ActiveSheet.AutoFilter.Range.Offset(1).Delete
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1
    
    Call Hulk 'Format cells, spacing alignment, box border removal, font and size standardization. Nothing too interesting in here.
    
Application.ScreenUpdating = True

End Sub
 
Upvote 0
I have not tested this since you have renamed sheets I am not sure if the initial XL2BBs still apply, so make sure you take a copy of your workbook first.
Also there is a always some personal preference involved but see if this helps.
Essentially
  • Removed all references to the following: Select, ActiveSheet, ActiveCell
    Note: You had an ActiveCell reference on the Send sheet without any Cell being selected in the code. I have assumed it was meant to be "A2"
  • Used set command so the sheet names are defined at the top, so you only have one change to make if you change the sheet names again.
  • Used With / End With - more efficient and clearer.

VBA Code:
Sub ColourMeElmo_AB()

Application.ScreenUpdating = False

'establish the criteria for colouring cells
Dim i As Long, r1 As Range, r2 As Range
Dim shtFltr As Worksheet, shtRec As Worksheet, shtSend As Worksheet

Set shtFltr = Sheets("Filter")
Set shtRec = Sheets("Receive")
Set shtSend = Sheets("Send")

'code for selecting which cells get coloured backgrounds
   On Error Resume Next
   For i = 6 To 41
      With shtFltr
          Set r1 = .Range("B" & i)
          Set r2 = .Range("L" & i & ":S" & i)
      End With
      If r1.Value = "" Then r2.Interior.Color = vbYellow
   Next i

' For "Receive" data that gets copied, pasted into the 'Receive' sheet from 'Filter', after formatting has taken place
    With shtFltr
        .Range("L6", .Range("L6").End(xlDown).End(xlToRight)).Copy
    End With
    
    With shtRec.Range("K2")
        .PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    End With
          
' For "Send" data that gets copied, pasted into the 'Send' sheet from 'fileter', after formatting has taken place
    With shtFltr
        .Range("B6", .Range("B6").End(xlDown).End(xlToRight)).Copy
    End With
    
    With shtSend.Range("A2")
        .PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    End With

' overwriting current table data with the newly filtered data
    With shtRec
        .Range("K2").CurrentRegion.Cut .Range("A2")
    End With

'copying the 'QC info' data from 'Send' to 'Receive'
    With shtSend
        .Range("Table1[QC Notes]").Copy Destination:=.Range("I2")
    End With
        
'Deleting blank rows in table
    With shtRec
        .ListObjects("Table2").Range.AutoFilter Field:=1, Criteria1:="="
        .AutoFilter.Range.Offset(1).Delete
        .ListObjects("Table2").Range.AutoFilter Field:=1
    End With

'delete all rows from 'Send' table
    With shtSend.Range("A2")                            ' <--- Check that this is meant to be "A2"
        If Not .ListObject Is Nothing Then
            .ListObject.DataBodyRange.Delete
        End If
    End With
        
'transfer data from 'Receive' to 'Send'
    shtRec.Range("A2").CurrentRegion.Offset(1, 0).Copy
    With shtSend.Range("A2")
        .PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    End With
    
'reset sheets
    shtSend.Columns("J:S").EntireColumn.Delete
    shtFltr.Range("A:T").Interior.Color = xlNone
        
'delete all rows from 'Receive' table
    With shtRec.Range("A2")
        If Not .ListObject Is Nothing Then
            .ListObject.DataBodyRange.Delete
        End If
    End With
        
'go to main sheet
    With shtSend
        .ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:="="
        .AutoFilter.Range.Offset(1).Delete
        .ListObjects("Table1").Range.AutoFilter Field:=1
    End With
    
    Call Hulk 'Format cells, spacing alignment, box border removal, font and size standardization. Nothing too interesting in here.
    
Application.ScreenUpdating = True

End Sub
 
Upvote 0
I have not tested this since you have renamed sheets I am not sure if the initial XL2BBs still apply, so make sure you take a copy of your workbook first.
Also there is a always some personal preference involved but see if this helps.
Essentially
  • Removed all references to the following: Select, ActiveSheet, ActiveCell
    Note: You had an ActiveCell reference on the Send sheet without any Cell being selected in the code. I have assumed it was meant to be "A2"
  • Used set command so the sheet names are defined at the top, so you only have one change to make if you change the sheet names again.
  • Used With / End With - more efficient and clearer.

VBA Code:
Sub ColourMeElmo_AB()

Application.ScreenUpdating = False

'establish the criteria for colouring cells
Dim i As Long, r1 As Range, r2 As Range
Dim shtFltr As Worksheet, shtRec As Worksheet, shtSend As Worksheet

Set shtFltr = Sheets("Filter")
Set shtRec = Sheets("Receive")
Set shtSend = Sheets("Send")

'code for selecting which cells get coloured backgrounds
   On Error Resume Next
   For i = 6 To 41
      With shtFltr
          Set r1 = .Range("B" & i)
          Set r2 = .Range("L" & i & ":S" & i)
      End With
      If r1.Value = "" Then r2.Interior.Color = vbYellow
   Next i

' For "Receive" data that gets copied, pasted into the 'Receive' sheet from 'Filter', after formatting has taken place
    With shtFltr
        .Range("L6", .Range("L6").End(xlDown).End(xlToRight)).Copy
    End With
   
    With shtRec.Range("K2")
        .PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    End With
         
' For "Send" data that gets copied, pasted into the 'Send' sheet from 'fileter', after formatting has taken place
    With shtFltr
        .Range("B6", .Range("B6").End(xlDown).End(xlToRight)).Copy
    End With
   
    With shtSend.Range("A2")
        .PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    End With

' overwriting current table data with the newly filtered data
    With shtRec
        .Range("K2").CurrentRegion.Cut .Range("A2")
    End With

'copying the 'QC info' data from 'Send' to 'Receive'
    With shtSend
        .Range("Table1[QC Notes]").Copy Destination:=.Range("I2")
    End With
       
'Deleting blank rows in table
    With shtRec
        .ListObjects("Table2").Range.AutoFilter Field:=1, Criteria1:="="
        .AutoFilter.Range.Offset(1).Delete
        .ListObjects("Table2").Range.AutoFilter Field:=1
    End With

'delete all rows from 'Send' table
    With shtSend.Range("A2")                            ' <--- Check that this is meant to be "A2"
        If Not .ListObject Is Nothing Then
            .ListObject.DataBodyRange.Delete
        End If
    End With
       
'transfer data from 'Receive' to 'Send'
    shtRec.Range("A2").CurrentRegion.Offset(1, 0).Copy
    With shtSend.Range("A2")
        .PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    End With
   
'reset sheets
    shtSend.Columns("J:S").EntireColumn.Delete
    shtFltr.Range("A:T").Interior.Color = xlNone
       
'delete all rows from 'Receive' table
    With shtRec.Range("A2")
        If Not .ListObject Is Nothing Then
            .ListObject.DataBodyRange.Delete
        End If
    End With
       
'go to main sheet
    With shtSend
        .ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:="="
        .AutoFilter.Range.Offset(1).Delete
        .ListObjects("Table1").Range.AutoFilter Field:=1
    End With
   
    Call Hulk 'Format cells, spacing alignment, box border removal, font and size standardization. Nothing too interesting in here.
   
Application.ScreenUpdating = True

End Sub
Hi Alex, Thanks for looking at this.

I did change the sheet names from 'Yesterday' to 'Send' and 'Today' to 'Receive'.

I took a lot of what you modified and added it to my own code but there are two parts of your modification that I left in its original form as I actually did want the sheets selected and I needed to transfer data from one sheet to the next.

Transfer from one sheet to the next.
VBA Code:
'copying the 'QC info' data from 'Send' to 'Receive'          <------ Destination needs to be 'shtRec' Range("I2").
    With shtSend
        .Range("Table1[QC Notes]").Copy Destination:=.Range("I2")
    End With

'go to main sheet           <----added the select 'shtSend' command back in as that is the final sheet I want to end up viewing.
    With shtSend
        .ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:="="
        .AutoFilter.Range.Offset(1).Delete
        .ListObjects("Table1").Range.AutoFilter Field:=1
    End With
 
Upvote 0
In that case:-
Change Item 1 to
VBA Code:
'copying the 'QC info' data from 'Send' to 'Receive'          <------ Destination needs to be 'shtRec' Range("I2").
shtSend.Range("Table1[QC Notes]").Copy Destination:=shtRec.Range("I2")

FOr Item 2 - Just finish with a select at the end of the code and leave what I had.
VBA Code:
    With shtSend
        .ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:="="
        .AutoFilter.Range.Offset(1).Delete
        .ListObjects("Table1").Range.AutoFilter Field:=1
    End With

'go to main sheet           <----added the select 'shtSend' command back in as that is the final sheet I want to end up viewing.
shtSend.Select
shtSend.Range("A2").Select
 
Upvote 0
In that case:-
Change Item 1 to
VBA Code:
'copying the 'QC info' data from 'Send' to 'Receive'          <------ Destination needs to be 'shtRec' Range("I2").
shtSend.Range("Table1[QC Notes]").Copy Destination:=shtRec.Range("I2")

FOr Item 2 - Just finish with a select at the end of the code and leave what I had.
VBA Code:
    With shtSend
        .ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:="="
        .AutoFilter.Range.Offset(1).Delete
        .ListObjects("Table1").Range.AutoFilter Field:=1
    End With

'go to main sheet           <----added the select 'shtSend' command back in as that is the final sheet I want to end up viewing.
shtSend.Select
shtSend.Range("A2").Select
Works. Thanks Alex.
 
Upvote 0

Forum statistics

Threads
1,214,605
Messages
6,120,476
Members
448,967
Latest member
visheshkotha

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