Solved Vbscript to copy Last row from Excel file to new excel file

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

jgriapon

Thread Starter
Joined
Aug 14, 2017
Messages
7
Please help me,
How to copy data from last row used of excel file to new excel file using vbscript?
 
Joined
Sep 4, 2003
Messages
4,916
Are you talking about a true stand-alone VBScript with .vbs extension or are you talking about running a VBA macro from within Excel?
 

jgriapon

Thread Starter
Joined
Aug 14, 2017
Messages
7
Rollin_Again - Thanks for the replay, I'm talking about vbcript (VBS) not VBA macro.
 
Joined
Sep 4, 2003
Messages
4,916
I assume you will be using this on an ongoing basis? After the VBS executes do you want the new workbook to remain open and visible so that you can manually save it to the location of your choice or are you wanting this to all happen hidden in the background and have it saved automatically?
 
Joined
Sep 4, 2003
Messages
4,916
Put the following code into a text file and then rename with .VBS extension and then double click it to execute. You'll need to change the file path and sheet name as I've comment below.

Code:
Set objExcel = CreateObject("Excel.Application")

'Change this path to reflect path of workbook containing data to copy from
Set objWorkbook = objExcel.Workbooks.Open("C:\Test\test.xlsx")

'Change sheet name to reflect name of sheet where data is being copied from
Set objWorksheet = objWorkbook.Worksheets("Sheet1")

vLastRow = objWorksheet.UsedRange.SpecialCells(11).Row

Set objWorkbookNew = objExcel.Workbooks.Add()
Set objWorksheet2 = objWorkbookNew.Worksheets("Sheet1")

objWorksheet.Rows(vLastRow & ":" & vLastRow).Copy
objWorksheet2.Range("A1").PasteSpecial
objWorkbook.Close
objExcel.Application.Visible = True
 

jgriapon

Thread Starter
Joined
Aug 14, 2017
Messages
7
Rollin_Again - Thanks a lot for your help, its work for me :)(y)
I'm just changed path of Excel file, The script running without error.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Top