Macro to Export a range within a sheet as an .xls file

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have tried to write code to export a range A1:U25 on sheet Sales 850105 as a .xls file


Howveer, when exported, it contains the the entire used range for eg A1:AB25

It would be appreciated if sommeone could kindly amend my code

Code:
 Sub Export_Sales850105()
         Application.ScreenUpdating = False
    
    Sheets(Array("Sales 850105")).Copy
    Worksheets(1).Range("A1:U25") = Worksheets(1).Range("A1:U25").Value2
    Worksheets(1).Cells.Hyperlinks.Delete
    
    ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & "Sales 850105 Upload" & ".xls", 56
    ActiveWorkbook.Close SaveChanges:=False
    
    Application.ScreenUpdating = True

End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try...

VBA Code:
 Sub Export_Sales850105()
 
    Dim sourceWorksheet As Worksheet
    Set sourceWorksheet = Worksheets("Sales 850105")
    
    Dim newWorkbook As Workbook
    Set newWorkbook = Workbooks.Add(xlWBATWorksheet)
    
    With sourceWorksheet.Range("A1:U25")
        newWorkbook.Worksheets(1).Range("A1").Resize(.Rows.Count, .Columns.Count).Value = .Value
    End With
 
    newWorkbook.SaveAs ThisWorkbook.Path & "\" & "Sales 850105 Upload" & ".xls", 56
    newWorkbook.Close savechanges:=False

End Sub

Hope this helps!
 
Upvote 0
Solution
Many Thanks Domenic. Code works perfectly
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,409
Members
448,959
Latest member
camelliaCase

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