+ Reply to Thread
Results 1 to 6 of 6

Save sheet as copy with range

Hybrid View

  1. #1
    Registered User
    Join Date
    10-15-2015
    Location
    NL
    MS-Off Ver
    2013
    Posts
    15

    Question Save sheet as copy with range

    Hi all,
    the solution is probably pretty simple but i cannot figure it out. The macro saves the workbook sheet as hard copy (whitout formulas). But he is copying the whole sheet. Iam looking for a ranged version (A1-K139)

    Sub Save_To_Excel()
    Dim wb As Workbook
        Sheets("Offerte").Copy
            With ActiveSheet.UsedRange
            .Value = .Value
        End With
        Set wb = ActiveWorkbook
        wb.SaveAs ThisWorkbook.Sheets("Offerte").Range("M1").Value & ".xlsx"
        wb.Close SaveChanges:=False
    
    End Sub
    Please help

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Save sheet as copy with range

    I think what you need to do is create a new workbook and copy and paste into it. Read up on the SaveAs command. I have not tested this code.

    Sub Save_To_Excel()
    Dim wb As Workbook
        Set wb = Workbooks.Add
        Sheets("Offerte").Range("$A$1:$K$139").Copy
            wb.Sheets(1).pastspecial xlPasteValues
        
        wb.SaveAs ThisWorkbook.Path & "\" & ThisWorkbook.Sheets("Offerte").Range("M1").Value & ".xlsx", _
            FileFormat = xlOpenXMLWorkbook
        wb.Close SaveChanges:=True
    End Sub
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,652

    Re: Save sheet as copy with range

    This copies includes formats as well.

    Sub Save_To_Excel()
        With Workbooks.Add(xlWBATWorksheet).Sheets(1)
            .Name = "Offerte"
            ThisWorkbook.Sheets("Offerte").Range("A1:K139").Copy .Range("A1")
            .Range("A1:K139").Value = .Range("A1:K139").Value
            .SaveAs ThisWorkbook.Sheets("Offerte").Range("M1").Value & ".xlsx"
            .Close SaveChanges:=False
        End With
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Save sheet as copy with range

    AlphaFrog: a quick question. On SaveAs, does the file format default to xlOpenXMLWorkbook? Too bad VB doesn't detect the extension and pick the right fileformat for you.

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,652

    Re: Save sheet as copy with range

    Quote Originally Posted by dflak View Post
    AlphaFrog: a quick question. On SaveAs, does the file format default to xlOpenXMLWorkbook? Too bad VB doesn't detect the extension and pick the right fileformat for you.
    Yes. I think it does default to xlOpenXMLWorkbook

    Quick heads up on your suggested code; I think you missed this bit.
    Thisworkbook.Sheets("Offerte").Range("$A$1:$K$139").Copy
    Otherwise it defaults to the ActiveWorkbook. In your code, the ActiveWorkbook is now the previously added new workbook.

  6. #6
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Save sheet as copy with range

    Got me on that one Yes, activeworkbook is the last workbook opened or created.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Help! - Copy Range (Sheet1,A10:F50), Paste Range (Sheet 2,A1:F41), Offset Range & Repeat
    By cjtimmer in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-30-2015, 06:27 PM
  2. Macro: Copy Active Sheet, Make Values Only, then Save Copy
    By brendangroff in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-10-2015, 04:34 PM
  3. Copy from one sheet to another sheet then save in another workbook
    By my14string in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-07-2014, 06:13 AM
  4. need to save sheet as a copy every time sheet is up dated
    By superchew in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-24-2013, 06:01 PM
  5. Replies: 4
    Last Post: 09-03-2013, 09:56 AM
  6. [SOLVED] Copy Data and paste it in new sheet and save new sheet as value of cell a2
    By VKS in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-03-2013, 08:55 AM
  7. Copy cells to new Sheet and Save Sheet
    By DadaaP in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-25-2013, 10:34 AM

Tags for this Thread

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