+ Reply to Thread
Results 1 to 4 of 4

Edit code to copy whole sheet

Hybrid View

Sirishgreen Edit code to copy whole sheet 05-08-2008, 07:15 AM
Sirishgreen Bump Bump Bump 05-12-2008, 06:50 AM
davesexcel Sheets("Sheet1").Copy Copies... 05-12-2008, 07:01 AM
Sirishgreen Thanks for that 05-12-2008, 08:06 AM
  1. #1
    Forum Contributor
    Join Date
    09-21-2007
    Posts
    126

    Edit code to copy whole sheet

    Hi,

    Somebody very kindly gave me this code and everything works except i would like to copy the whole sheet not just the cells contents for a given range (I need the whole sheet formatting and all) at the minute its just the cell contents getting copied within a given range.

    Help!

    Sub list_files()
    Dim F As String
    Cells(2, 1).Select
    F = Dir("C:\Documents and Settings\user name\My Documents\Test Results\" & "*.xls")
    Do While Len(F) > 0
    ActiveCell.Formula = F
    ActiveCell.Offset(1, 0).Select
    F = Dir()
    Loop
    x = Worksheets("sheet1").Cells(Rows.Count, 1).End(xlUp).Row
    MsgBox "there are " & x - 1 & " files in this folder"
    For a = 2 To x
    d = 2
    h = Worksheets("sheet1").Cells(a, 1)
    g = Left(h, Len(h) - 4)
    Sheets.Add.Name = g
    Worksheets("sheet1").Activate
    For c = 2 To 50 'No of rows
    For b = 2 To 20 'No of columns
    m = Chr(b + 64)
    Worksheets("Sheet1").Cells(1, 1) = "='C:\Documents and Settings\user name\My Documents\Test Results\[" & Cells(a, 1) & "]January'!" & m & c
    Worksheets(g).Cells(c + 2, b) = Worksheets("Sheet1").Cells(1, 1)
    Next b
    d = d + 1
    Next c
    Next a
    MsgBox "Completed"
    End Sub
    Thanks
    Simon.

  2. #2
    Forum Contributor
    Join Date
    09-21-2007
    Posts
    126

    Bump Bump Bump

    Please can somebody help me with this.

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525
    Sheets("Sheet1").Copy
    Copies sheet 1 into a new workbook
    Last edited by davesexcel; 05-13-2008 at 01:21 AM.

  4. #4
    Forum Contributor
    Join Date
    09-21-2007
    Posts
    126

    Thanks for that

    The problem is there is no notation in this code and as I am quite new to vba i dont really understand how i would change the code to enter the code you suggested. I can identify where the range is selected in the code but, there are other places where it looks like its selecting a range.

    Where would i place suggested code to get it to work.

    Thanks again

    Simon Green

+ 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