HELP with VBA modification

JoAv

New Member
Joined
May 14, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hello everyone,
I need some help in recompiling this code.
It is meant to copy a range from a sheet, paste the range in a new sheet and save it at a given directory.
It works as expected, except that it copies and pasted the range at A53:I54, while I want it to be pasted at A1.
Plus, if possible I would like the formatting to be pasted as well.

Sub New_Sheet()
Dim wbkT As Workbook
Dim wshS As Worksheet
Dim wshT As Worksheet
Dim sPath As String
Dim sDate As String
Dim sCity As String
Dim sAddress As String
Dim sFile As String
Set wshS = ThisWorkbook.Worksheets("Formulas")
Set wbkT = Workbooks.Add(xlWBATWorksheet)
Set wshT = wbkT.Worksheets(1)
wshT.Range("A53:I54").Value = wshS.Range("A53:I54").Value
sPath = CreateObject("WScript.Shell").SpecialFolders("Desktop")
sDate = Format(Date, "dd mm yyyy")
sPath = sPath & "\Delivery\" & sDate
sCity = wshS.Range("A5").Value
sPath = sPath & "\" & sCity
sAddress = wshS.Range("A6").Value
sPath = sPath & "\" & sAddress
sFile = "Station.xlsx"
sPath = sPath & "\" & sFile
wbkT.SaveAs Filename:=sPath, FileFormat:=xlOpenXMLWorkbook
wbkT.Close
End Sub

Thank you very much.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try replacing this line:
VBA Code:
    wshT.Range("A53:I54").Value = wshS.Range("A53:I54").Value

with these lines:
VBA Code:
    wshS.Range("A53:I54").Copy
    wshT.Range("A1").PasteSpecial Paste:=xlPasteValues
    wshT.Range("A1").PasteSpecial Paste:=xlPasteFormats

(Tip: when posting code, please try to use 'code tags' to format the code as I have done above
it makes the code easier to read.)
 
Upvote 0
Solution
Try replacing this line:
VBA Code:
    wshT.Range("A53:I54").Value = wshS.Range("A53:I54").Value

with these lines:
VBA Code:
    wshS.Range("A53:I54").Copy
    wshT.Range("A1").PasteSpecial Paste:=xlPasteValues
    wshT.Range("A1").PasteSpecial Paste:=xlPasteFormats

(Tip: when posting code, please try to use 'code tags' to format the code as I have done above
it makes the code easier to read.)
Worked perfect!
Thanks a ton!!
Will keep the code tags in next post in mind!!
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,697
Members
449,117
Latest member
Aaagu

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