+ Reply to Thread
Results 1 to 5 of 5

Macro to copy columns into new sheets

  1. #1
    Registered User
    Join Date
    01-29-2007
    Posts
    69

    Macro to copy columns into new sheets

    Hi,
    I currently work with a worksheet that is evolving over time. I use it to quote customers based on house plans. There are a lot of plans involved so i have one workbook that has many worksheets for each house plan material list with pricing. Also i have other workbooks one for each plan that has sheets for each upgrade option builder offers. So by saying that, when i do have a change i want to make to the template i have a lot of copying and pasting to do. Right now i copy the template to a new book and copy and paste the old data into the updated copied template then rename the tabs to reflect what it is. This has become very very cumbersome due all of the data i have collected and continue to collect each day.
    I was wondering if i could create some sort of macro to open a workbook, copy specific columns in a range ( a2:a70 and c2:c70 ) for example and possibly a couple of individual cells, open my template, and copy it into the book i am copying the columns from and rename each tab the same name with a 1 or something behind it to distinguish between the old sheet and the new updated sheet with the data copied into it.
    Is this impossible? I haven't found so far that excel that a lot of things in excel are impossible so any help would be great.
    If i need to send in a copy of the sheets i am talking about i will.

    Thanks again.

  2. #2
    Registered User
    Join Date
    01-29-2007
    Posts
    69

    Re: Macro to copy columns into new sheets

    To help better explain my question, please see attached sheets.

    Workbook Plans.xls is an example of what my workbook would look like with the exception of data i deleted in a4:a86 and
    c4:c86.

    workbook template.xls is of course my template that when i need to make changes i would make it there. Once done, I would
    like a macro to open the workbook "plans.xls" copy the worksheet from "template.xls" into "plans.xls" and copy cells
    a4:a86, c4:c86 and b1:d1 to the new sheet that was copied and rename the tab same name and delete the old one. There will be multiple sheets in plans.xls so i will need it to do it for each of tab until done. see attached

    Thanks
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    01-29-2007
    Posts
    69

    Re: Macro to copy columns into new sheets

    any suggestions?

  4. #4
    Registered User
    Join Date
    01-29-2007
    Posts
    69

    Re: Macro to copy columns into new sheets

    Quote Originally Posted by JESSIER4025 View Post
    To help better explain my question, please see attached sheets.

    Workbook Plans.xls is an example of what my workbook would look like with the exception of data i deleted in a4:a86 and
    c4:c86.

    workbook template.xls is of course my template that when i need to make changes i would make it there. Once done, I would
    like a macro to open the workbook "plans.xls" copy the worksheet from "template.xls" into "plans.xls" and copy cells
    a4:a86, c4:c86 and b1:d1 to the new sheet that was copied and rename the tab same name and delete the old one. There will be multiple sheets in plans.xls so i will need it to do it for each of tab until done. see attached

    Thanks
    I attempted to create the macro i needed but i need further assistance on what i have done so far. I tested it and it works almost like i wanted to.
    There may be a few unneccesary clicks in the macro that may need to be removed and if so please let me know what i can take out.
    I think the last part of it is that i would rather it go through the entire workbook and replace all worksheets like i got it to do in the macro and rename the new sheet the same name as the old and delete the old tabs when finished.
    see my macro below.
    Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 2/6/2012 by rstevens1
    '

    '
    Windows("template.xls").Activate
    Sheets("2012 DRH Bid Template ").Select
    Sheets("2012 DRH Bid Template ").Copy Before:=Workbooks("plans.xls").Sheets(1 _
    )
    Sheets("2012 DRH Bid Template 11").Select
    ActiveWindow.SmallScroll Down:=-117
    Range("A4:A86").Select
    Selection.Copy
    Sheets("2012 DRH Bid Template ").Select
    ActiveWindow.SmallScroll Down:=-105
    Range("A4").Select
    ActiveSheet.Paste
    Range("C4").Select
    Sheets("2012 DRH Bid Template 11").Select
    Range("C4:C86").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("2012 DRH Bid Template ").Select
    ActiveSheet.Paste
    Sheets("2012 DRH Bid Template ").Select
    Sheets("2012 DRH Bid Template ").Name = "2012 SHEET COPY"
    Range("B37").Select
    Sheets("2012 DRH Bid Template 11").Select
    End Sub

  5. #5
    Registered User
    Join Date
    01-29-2007
    Posts
    69

    Re: Macro to copy columns into new sheets

    I have received some help with a new macro to do what i needed but i am getting a subscript out of range error.
    I have checked the file names and it appears all is ok.

    Can someone look over the code and let me know if something appears wrong?

    Sub Macro1
    'Assign Workbook Variables
    WBSource = "template.xlsm"
    WBTarget = "plans.xlsx"

    'Assign Source and Target Range Variables
    SourceRng1 = "A4:A86"
    SourceRng2 = "C4:C86"
    SourceRng3 = "B1:D1"
    TargetRng1 = "A4"
    TargetRng2 = "C4"
    TargetRng3 = "B1"

    'Assign Source and Target WorkSheet Name Variables
    SourceSheet1 = "2012 DRH Bid Template"
    Windows(WBTarget).Activate
    Set wkbTarget = ThisWorkbook

    For Each ws In Worksheets
    Select Case ws.Name
    Case "Table of Contents", "Taxes and Labor"
    ' do nothing in above worksheet names
    Case Else
    Var1 = ws.Name
    Workbooks(WBSource).Sheets(SourceSheet1).Copy Before:=Workbooks(WBTarget).Sheets(Var1)
    Var2 = ActiveSheet.Name
    'Copy Ranges to Targets
    Sheets(Var1).Range(SourceRng1).Copy Sheets(Var2).Range(TargetRng1)
    Sheets(Var1).Range(SourceRng2).Copy Sheets(Var2).Range(TargetRng2)
    Sheets(Var1).Range(SourceRng3).Copy Sheets(Var2).Range(TargetRng3)
    'Remove old sheet and rename new
    Application.DisplayAlerts = False
    Sheets(Var1).Delete
    Application.DisplayAlerts = True
    ActiveSheet.Name = Var1
    End Select
    Next ws
    End Sub
    Last edited by JESSIER4025; 02-07-2012 at 11:41 AM. Reason: code change

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1