Copy Rows to Different Tabs

matthewrlong

New Member
Joined
Jan 18, 2017
Messages
11
Hello Everyone!

I'm new to this forum and just hope I'm doing things correctly!

The current issue I am faced with is how to populate a row, depending on the condition typed in the end cell, to the corresponding tab.

For example:
Row 2 thru Row 5 have information in cells A-N. In cell "O2" I would like to type a letter (C, L, H) and depending on the letter typed in "O2" the row information will be moved to its corresponding sheet. The name of the sheets we have setup are CNC Ticket, Lumber Ticket, Hardware Ticket.

I am using a excel 2016
All help is appreciated!
ML
 
So here is the code that I have changed a little just trying to troubleshoot. A decision was made to add an "Optimization Ticket".
I am still getting the "Run-time error '9': Subscript out of range" debug error.

a = 2
ws = ""
rows.count = 1048576
xLup = -4162

Code:
[CommandButton1] [Click]
_________________________________________________________

Option Explicit
_________________________________________________________


Sub CommandButton1_Click()
Dim a As Integer
Dim ws As String
Dim sh As Worksheet

For Each sh In ThisWorkbook.Worksheets
If sh.Name <> "CNC Ticket" Then
If sh.Name <> "Lumber Ticket" Then
If sh.Name <> "Optimization Ticket" Then
If sh.Name <> "Hardware Ticket" Then
With sh
For a = 2 To .Cells(.Rows.Count, 2).End(xlUp).Row
Select Case .Cells(a, 15).Value
Case Is = "C"
ws = "CNC Ticket"
Case Is = "L"
ws = "Lumber Ticket"
Case Is = "O"
ws = "Optimization Ticket"
Case Is = "H"
ws = "Hardware Ticket"
End Select
.Range("B" & a & ":N" & a).Copy Worksheets(ws).Range("B" & Rows.Count).End(xlUp).Offset(1)
Next a
End With
End If
End If
End If
End If
Next sh
End Sub


Here is an example item sheet. We have varying item sheets 730,738,746,900,903,950.
Cab# is in cell B5



900 Serving LineWS
JOB #16600CUSTOMERMatt Test
DATELOCATIONSt.Joseph MO
DESCRIPTIONTOTAL CABINETS1
Cab #QtyMaterialThickWidthLengthPart DescriptionNotesEdge1Edge2Edge3Edge4
9001MDF0.51212Panelsand1234pidC
9001PB0.51212Subsand1234pidC
9001Lam0.51212topsand1234pidL
9001Lam0.51212bottomsand1234pidL
9001Lam0.51212frontsand1234pidO
9001Plastic0.51212TrimsandpidO
9002Plastic0.51212TrimsandpidO
9003Plastic0.51212TrimsandpidS
9001Corian0.51212topsand1234pidS
9001Corian0.51212topsand1234pidH
9001Corian0.51212topsand1234pidH

<tbody>
</tbody>

Here is an example "ticket" sheet
On this sheet and the other "ticket" sheets, CAB# is in A6




CNC TICKET
JOB #16600CUSTOMERMatt Test
DATELOCATIONSt.Joseph MO
DESCRIPTION
Cab #QtyMaterialThickWidthLengthPart DescriptionNotesEdgeEdge2Edge3Edge4

<tbody>
</tbody>


Im just trying to break everything down for you.

Thank you,
Matthew L.
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Try this...
Code:
Sub CommandButton1_Click()
    Dim a As Integer
    Dim ws As String
    Dim sh As Worksheet
    
    For Each sh In ThisWorkbook.Worksheets
        If sh.Name <> "CNC Ticket" Then
            If sh.Name <> "Lumber Ticket" Then
                If sh.Name <> "Optimization Ticket" Then
                    If sh.Name <> "Hardware Ticket" Then
                        With sh
                            For a = 6 To .Cells(.Rows.Count, 2).End(xlUp).Row
                                Select Case .Cells(a, 15).Value
                                    Case Is = "C"
                                    ws = "CNC Ticket"
                                    Case Is = "L"
                                    ws = "Lumber Ticket"
                                    Case Is = "O"
                                    ws = "Optimization Ticket"
                                    Case Is = "H"
                                    ws = "Hardware Ticket"
                                End Select
                                .Range("B" & a & ":N" & a).Copy Worksheets(ws).Range("A" & Rows.Count).End(xlUp).Offset(1)
                            Next a
                        End With
                    End If
                End If
            End If
        End If
    Next sh
End Sub
 
Upvote 0
That works BEAUTIFULLY!! thank you so much Dangelor!! major props to you.

I'm working on another button now and will definitely contact you if i need help.
I'm gonna work on teaching myself.

Thank you
ML
 
Upvote 0
Sorry to bother you again Dangelor but I need some more help if you don't mind.
I'm not sure if this is the proper way to use the forum or not so I do apologize in advance!

I'm coming back to you because you are a very reliable source.

So here is the deal. I have now been asked to take the information on the "Optimization Ticket" and copy only certain information over.

I am using the following code.

Sub CommandButton2_Click()
Dim a As Integer
Dim ws As String

With Worksheets("Optimization Ticket")
For a = 6 To .Cells(.Rows.Count, 2).End(xlUp).Row
Select Case .Cells(a, 16).Value
Case Is = ""
ws = "Optimization Ticket"
End Select
.Range("B" & a & ":L" & a).Copy Worksheets("Process Ticket").Range("A" & Rows.Count).End(xlUp).Offset(1)
Next a
End With
End Sub

Now it works fine except instead of grabbing the value from cell "C6" (which is our Quantity) it wants to grab the formula.
Is there any way to grab just numeric value in cell "C6".

Thank you
ML
 
Upvote 0
This may work...
Code:
Sub CommandButton2_Click()
    Dim a                As Integer
    Dim ws               As String
    Dim vRow             As Variant

    With Worksheets("Optimization Ticket")
        For a = 6 To .Cells(.Rows.Count, 2).End(xlUp).Row
            Select Case .Cells(a, 16).Value
                Case Is = ""
                    ws = "Optimization Ticket"
            End Select
            vRow = .Range("B" & a & ":L" & a)
            Worksheets("Process Ticket").Range("A" & Rows.Count).End(xlUp).Offset(1) _
                    .Resize(UBound(vRow, 1), UBound(vRow, 2)) = vRow
        Next a
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,614
Members
449,090
Latest member
vivek chauhan

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