Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 688

VBScript To copy the specific columns only to specific cell in Excel 365

$
0
0
Hi,

I'm trying to copy specific column values (range "M:P") from one excel 365 file to the other on the range "M:P", using VBScript.

Master.xlsx file structure

Name:  nm13f.jpg
Views: 31
Size:  14.6 KB

Copy_2022.xlsx file structure (after the copy columns from Master.xlsx)

Name:  dRVLx.jpg
Views: 31
Size:  21.0 KB

The copy of specific column values working correctly from Master.xlsx file to Copy_2022.xlsx file.

But the problem is that the copied columns values start from cell M1 and not from cell M4 on Copy_2022.xlsx file.

This is what I've tried.

Code:

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Open("C:\Master.xlsx")
Set objWorkbook2 = objExcel.Workbooks.Open("C:\Copy_2022.xlsx")

Set objWorksheet = objWorkbook.Worksheets(1)
objWorksheet.Activate
objWorkbook2.Worksheets(1).UnProtect

Set objRange = objWorkSheet.Range("M:P").EntireColumn
objRange.Copy

Set objWorksheet2 = objWorkbook2.Worksheets(1)
objWorksheet.Activate

Set objRange = objWorkSheet2.Range("M:P")
objWorksheet.Paste(objRange)

objWorkbook2.Save
objWorkbook2.Close
objWorkbook.Close

objExcel.Quit
Set objExcel = Nothing

Any suggestion?
Attached Images
  

Viewing all articles
Browse latest Browse all 688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>