Copy rows based on cell value to match with tab name when you do not have a set location

JakariKryze

New Member
Joined
Dec 14, 2021
Messages
10
Office Version
  1. 365
Platform
  1. Windows
I have a master list worksheet called "BlackBoard" that this information comes from. All rows in column A with the 12.01.21 dates need to be copied to the worksheet "12.01.21". This needs to be done for each day of the month so 31 worksheets. I am new to this and i am stuck trying to Frankenstein this together from a bunch of other answers, can anyone help please?
Here is where i am at so far..
Sub example()
Dim wkSht As Worksheet
Dim c As Range

For Each c In Sheets("BlackBoard").Range("A2:A800")
If c.Value = wkSht.Name Then
'this is where i am stuck i don't know how to get it to paste to an unidentified worksheet based on what is found in column A which the worksheets are named after
End If
Next Cell
End Sub
VBA Code:
Retail Tran DateProduct Department NameSum of Product Net Sales AmtSum of Product Tax Amount
12.01.21 Gift Boxes - No Tax
$50.00​
$0.00​
12.01.21 Misc - No Tax
$248.65​
$0.00​
12.01.21Misc - Tax
$272.35​
$19.84​
12.01.21Mixes
$28.80​
$1.40​
12.01.21 Swag - Tax
$23.85​
$0.00​
12.01.21 Thistle & Rose - Ta
$29.75​
$0.88​
12.02.21 Drinks - Tax
$11.70​
$0.90​
12.02.21 Gift Boxes - No Tax
$38.85​
$0.00​
12.02.21Misc - No Tax
$150.00​
$0.00​
12.02.21Misc - Tax
$2,886.36​
$202.06​
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try:
VBA Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim v As Variant, i As Long
    v = ActiveSheet.Range("A2", ActiveSheet.Range("A" & Rows.Count).End(xlUp)).Value
    With CreateObject("scripting.dictionary")
       For i = 1 To UBound(v)
            If Not .exists(v(i, 1)) Then
                .Add v(i, 1), Nothing
                With ActiveSheet
                    .Range("A1").CurrentRegion.AutoFilter 1, v(i, 1)
                    .AutoFilter.Range.Offset(1).Copy Sheets(v(i, 1)).Cells(Sheets(v(i, 1)).Rows.Count, "A").End(xlUp).Offset(1)
                End With
            End If
       Next i
    End With
    ActiveSheet.Range("A1").AutoFilter
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Try:
VBA Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim v As Variant, i As Long
    v = ActiveSheet.Range("A2", ActiveSheet.Range("A" & Rows.Count).End(xlUp)).Value
    With CreateObject("scripting.dictionary")
       For i = 1 To UBound(v)
            If Not .exists(v(i, 1)) Then
                .Add v(i, 1), Nothing
                With ActiveSheet
                    .Range("A1").CurrentRegion.AutoFilter 1, v(i, 1)
                    .AutoFilter.Range.Offset(1).Copy Sheets(v(i, 1)).Cells(Sheets(v(i, 1)).Rows.Count, "A").End(xlUp).Offset(1)
                End With
            End If
       Next i
    End With
    ActiveSheet.Range("A1").AutoFilter
    Application.ScreenUpdating = True
End Sub
Run-time error'9': subscript out of range- im so new to this that i dont understand what that means?
 
Upvote 0
Which line of code is highlighted when you click "Debug"? Make sure that all the sheets for each date in column A exist.
 
Upvote 0
Which line of code is highlighted when you click "Debug"? Make sure that all the sheets for each date in column A exist.
.AutoFilter.Range.Offset(1).Copy Sheets(v(i, 1)).Cells(Sheets(v(i, 1)).Rows.Count, "A").End(xlUp).Offset(1)
This was the highlighted line in the debuger
 
Upvote 0
That most likely means that one or more sheets named based on the dates in column A don't exist. Based on the data you posted, you should have two sheets named "12.01.21" and "12.02.21".
 
Upvote 0
That most likely means that one or more sheets named based on the dates in column A don't exist. Based on the data you posted, you should have two sheets named "12.01.21" and "12.02.21".
i found the error and this works great.
{null}{null}
{null}​
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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