Click here to Skip to main content
15,851,242 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a excel file, i want to copy the last used row from sheet1 to sheet2 use vbscript.
can anyone help me?

What I have tried:

Here is the code:

Set x6 = CreateObject("Excel.application")
 Set XlBook = x6.Workbooks.Open(".xlsx")
 x6.Visible = True
  Set Xlsheet = XlBook.Worksheets("Sheet2")
 Set Xlsheet1 = XlBook.Worksheets("sheet1")
 With Xlsheet
 'Dim lastrow
      Xlsheet1.Range("A:D").Copy .Range(.Cells(1, j + 2), .Cells(6, j + 2))
 End With
Updated 20-Aug-17 16:05pm

1 solution

Have you tried the "Record Macro" button?

1. Go to any cell,
2. Turn record macro on
3. Press CTRL+HOME
6. Press CTRL+C
7. Click on "Sheet 2"
8. Stop recording - the code is now generated for you using Excel Record Macro function

Go to VB code generated, review, optimise, test, publish...
Share this answer
Member 13356330 20-Aug-17 21:51pm    
Graeme_Grant - Thanks for your reply, how to use VBSCRIPT?
Graeme_Grant 20-Aug-17 22:04pm    
Look at the code generated... Excel tells you how. Do you know how to access the code editor window?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900