Results 1 to 1 of 1

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

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2022
    Posts
    3

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

    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: 569
Size:  14.6 KB

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

    Name:  dRVLx.jpg
Views: 564
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?
    Last edited by LandoMarossi; Jun 10th, 2022 at 02:30 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width