Consulting

Results 1 to 5 of 5

Thread: Copy selected columns to new sheets.

  1. #1
    VBAX Regular pegbol's Avatar
    Joined
    Feb 2005
    Posts
    45
    Location

    Copy selected columns to new sheets.

    .
    Hello Masters,

    I got the attached file from contextures.com The code of the file creates new Sheets for records of column C 'Rep'.

    I would appreciate help me to include to this VBA code the next:
    To copy to new Sheets all the format of the sheet "template".
    To copy to new Sheets the records of "Sheet1" only for the columns of the sheet "template".
    To sort the column 'Item' of the new Sheets

    Thanks so much in advance for your kind help.

    regards,
    Pedro.

    PS. Could it be possible to add totals to columns 'Units' and 'Total' of the new sheets?.
    .

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Try this macro.

    Option Explicit
    
    Sub Macro1()
    Dim i               As Long
    Dim LastRow         As Long
    Dim Row             As Long
    Dim ws              As Worksheet
    With Sheets("Sheet1")
            LastRow = .Range("A65536").End(xlUp).Row
            For i = 2 To LastRow
                On Error Resume Next
                Set ws = Sheets(.Range("C" & i).Text)
                If Err <> 0 Then
                    Sheets("Template").Copy After:=Sheets(Sheets.Count)
                    Set ws = Sheets(Sheets.Count)
                    ws.Name = .Range("C" & i).Text
                End If
                On Error GoTo 0
                Row = ws.Range("B65536").End(xlUp).Row + 1
                ws.Range("B" & Row).Value = .Range("C" & i).Text
                ws.Range("C" & Row).Value = .Range("B" & i).Text
                ws.Range("D" & Row).Value = .Range("E" & i).Value
                ws.Range("E" & Row).Value = .Range("D" & i).Text
                ws.Range("F" & Row).Value = .Range("G" & i).Value
            Next i
        End With
    End Sub

  3. #3
    VBAX Regular pegbol's Avatar
    Joined
    Feb 2005
    Posts
    45
    Location

    Awesome!!!

    .
    Just Awesome!!!!!


    As always. Thanks and thanks so much Jake!!!.


    best and kindest regards,
    Pedro
    La Paz, BOLIVIA.
    .

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You're Welcome

    Take Care

  5. #5
    VBAX Regular pegbol's Avatar
    Joined
    Feb 2005
    Posts
    45
    Location
    .
    Hello Jake,

    I am not sure if it is correct to reopen a thread. If it's not, I apologize.

    I made some corrrections to my template sheet and I tried to make a modification to the code. Unfortunately, I couldn`t.

    I can't leave empty the first row (of every new sheet).
    I can't include a sum to the last row and include an operation to column F (of every new sheet).

    So, one more time I kindly ask your valuable support.

    I enclose the code with a little modification I did it.

    Thanks so much again for your help.

    regards,
    Pedro.
    .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •