I am new to VB and I am going to use it for Quick Test Pro (QTP). I am having a problem to copy data from one Excel to another Excel file with specific rows and columns. Here is the scenario:
- I have one Excel file with more than 20 rows. Let say 100 rows.
- I need to copy the first row, then the 2nd to 20th rows, then save it to a different file.
- I need to copy the first row, then the 21st to 41st rows, then save it to a different file.
- Then same thing for the rest. Until there is NO value on the last row.
I need to copy the first row, because this is where the title/header is that I need.
So far, this is what I did. But it only copies the single column and NOT the columns that I want:
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook1 = objExcel.Workbooks.Open("C:\Report\CMaxx_File1.xlsx")
ObjExcel.Visible = True
Set objWorkbook2 = objExcel.Workbooks.Open("C:\Report\CMaxx_File2.xlsx")
objWorkbook1.Worksheets("Sheet1").Range("A1:A21").Copy
objWorkbook2.Worksheets("Sheet1").Range("A1:A21").PasteSpecial
objWorkbook2.Save