Copy sheet values onto another workbook

avatron

New Member
Joined
Apr 29, 2020
Messages
4
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi Everyone,

I would like to copy a sheet end of every month that contains formulas (vlookup) into a another woorkbook but only values and no formulas. So basically this would be an archiving. This two different files are in different folders. My issue is due to the name of the sheet different every month (named by current month, right now is april) i would need to change the name in VBA every month to do the job properly.

My question is how can i specify to copy always the previous sheet in the workbook, and how to specify to place it with the original sheet name to the end of the target workbook?

VBA Code:
Dim OutputFile As Workbook
Dim Inputpath As String
Dim Outputpath As String '


Set InputFile = ActiveWorkbook
Set OutputFile = Workbooks.Open("C:\Users\xxxx\Desktop\Archive.xlsm")


InputFile.Sheets("March").Activate
InputFile.Sheets("March").Range("A1:O360").Copy


OutputFile.Sheets("Sheet1").Activate
OutputFile.Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues

OutputFile.Close savechanges:=True


Thanks for help!
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi & welcome to MrExcel.
How about
VBA Code:
Dim OutputFile As Workbook, InputFile As Workbook
Dim Sht As String
Dim Outputpath As String '


Set InputFile = ActiveWorkbook
Set OutputFile = Workbooks.Open("C:\Users\xxxx\Desktop\Archive.xlsm")
Sht = MonthName(Month(Date) - 1, 0)

InputFile.Sheets(Sht).Range("A1:O360").Copy


OutputFile.Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues

OutputFile.Close savechanges:=True
Rather than pasting to sheet1, do you need to create a new sheet in the output file?
 
Upvote 0
Hi Fluff,

Thanks, it worked well!

Don't need to pasting to sheet1, it would be the best if using the same name as it was originally.
 
Upvote 0
Will the sheet already exist, or does it need to be created?
 
Upvote 0
Need to be created, or even can be copied the whole sheet without vlookup formula.
 
Upvote 0
Ok, how about
VBA Code:
Dim OutputFile As Workbook, InputFile As Workbook
Dim Sht As String
Dim Outputpath As String


Set InputFile = ActiveWorkbook
Set OutputFile = Workbooks.Open("C:\Users\xxxx\Desktop\Archive.xlsm")
Sht = MonthName(Month(Date) - 1, 0)

With OutputFile
   InputFile.Sheets(Sht).Copy , .Sheets(.Sheets.Count)
   With .Sheets(Sht).UsedRange
      .Value = .Value
   End With
End With
OutputFile.Close savechanges:=True
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,051
Messages
6,122,871
Members
449,097
Latest member
dbomb1414

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