Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9009369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:10:26+00:00 2026-06-16T02:10:26+00:00

I am trying to copy the sheet1 range data to sheet2 range but nothing

  • 0

I am trying to copy the sheet1 range data to sheet2 range but nothing gets copied. This is the full code which I was trying to achieve something but got stuck in the basic place. Please help

Edit: I tried the Macro just now and the same thing happened with this code. Please see the snapshot where you can see that Snap 1 contains source data and also selected but does not get copied to Snap 2. However the ranges are selected there.

  Sub copy()
      Range("A1:J4").Select
      Selection.copy
      Sheets("Sheet2").Select
      ActiveSheet.Paste
      Application.CutCopyMode = False
      ActiveWorkbook.Save
  End Sub

enter image description here

enter image description here

UpDate

Style-1

     Option Explicit


     Dim objSheet1,objSheet2,TotalRows,TotalcolCopy,strPathExcel1

     Dim oXls  : Set oXls = CreateObject("Excel.Application")
     Dim aData ': aData = oWb.Worksheets(1).Range("$A2:$C10")
     Dim dicP  : Set dicP = CreateObject("Scripting.Dictionary")

     strPathExcel1 = "D:\WIPData\AravoMacro\Finalscripts\GE_Wing_To_Wing_Report.xlsx"
     oXls.Workbooks.open strPathExcel1

     Set objSheet1 = oXls.ActiveWorkbook.Worksheets(1)
     Set objSheet2 = oXls.ActiveWorkbook.Worksheets(2)


     TotalRows=oXls.Application.WorksheetFunction.CountA(objSheet1.Columns(1)) - 3
     TotalcolCopy=oXls.Application.WorksheetFunction.Match("Parent Business Process ID", objSheet1.Rows(3), 0)

   objSheet1.Range(objSheet1.Cells(4,1),objSheet1.Cells(TotalRows,TotalcolCopy)).Copy(objSheet2.Range("A1"))

    '=======================
     oXls.ActiveWorkbook.SaveAs strPathExcel1
     oXls.Workbooks.close
     oXls.Application.Quit
    '======================

Style-2

  Option Explicit


  Dim objSheet1,objSheet2,TotalRows,TotalcolCopy,strPathExcel1
  Dim oFS   : Set oFS  = CreateObject("Scripting.FileSystemObject")
  Dim oXls  : Set oXls = CreateObject("Excel.Application")
  Dim aData ': aData    = oWb.Worksheets(1).Range("$A2:$C10")
  Dim dicP  : Set dicP = CreateObject("Scripting.Dictionary")

  oXls.Workbooks.Open(oFs.GetAbsolutePathName("Test.xlsx"))
  Set objSheet1 = oXls.ActiveWorkbook.Worksheets(1)
  Set objSheet2 = oXls.ActiveWorkbook.Worksheets(2)


  TotalRows=oXls.Application.WorksheetFunction.CountA(objSheet1.Columns(1)) - 3
  TotalcolCopy=oXls.Application.WorksheetFunction.Match("Parent Business Process ID", objSheet1.Rows(3), 0)

  objSheet1.Range(objSheet1.Cells(4,1),objSheet1.Cells(TotalRows,TotalcolCopy)).Copy(objSheet2.Range("A1"))

  '=======================
  oXls.ActiveWorkbook.SaveAs "Test.xlsx"
  oXls.Workbooks.close
  oXls.Application.Quit
  '======================

Could you people tell me what differences between Style-1 and Style-2.Because in Style-1 all the copied data get saved,which is not the case in Style-2. This design issue mainly the overall problem i was facing from morning.

In what way Style-2 is not perfect?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:10:28+00:00Added an answer on June 16, 2026 at 2:10 am

    The simplest way to copy from one range to another would be to recoding macro. Looking at your code, what are the values you are getting for TotalRows and LastCol? Assuming you have matching data returned from your Match(), so there’re rows to copy`

    Option Explicit
    
    Sub CopyPastes()
        Dim rng1 as Range
        Dim rng2 as Range
    
        Set rng1 = Sheets(1).Range("B2:C12")
        Set rng2 = Sheets(2).Range("B2")
        rng1.Copy
        rng2.PasteSpecial xlPasteValues
    End Sub
    

    So in your case, can you keep it simple? Remove the following line. Just specify the starting Range of the Sheet2 and try out. You do not have to worry about resize at this point.

    replace this,

    ObSheet2.Range(ObSheet2.Cells(4,1),ObSheet2.Cells(TotalRows,LastCol)).PasteSpecial
    

    with either: coz you are missing paste special argument

    ObSheet2.Range(ObSheet2.Cells(4,1),ObSheet2.Cells(TotalRows,LastCol)) _ 
    .PasteSpecial xlPasteValues
    

    or : here without any fancy cells, but direct range

    ObSheet2.Range(ObSheet2.Range("A4").PasteSpecial xlPasteValues
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to copy DataGridView data to Excel and I am using this
I am trying to copy a column from one sheet to another. The code
I'm currently trying to copy data from table into another by using a SELECT
I am trying to write a script which will automate a copy/paste of employee
I'm trying to copy the content of the clipboard to a Textbox but i
I'm trying to copy information from an iframe to my document, I wrote this
I am trying to copy data starting at a row with cell with value
I am trying to get Excel data, which was mapped using a grid/matrix mapping
I'm relatively inexperienced in VBA code, but have a workbook that I am trying
Trying to copy a char *str to char c[] but getting segmentation fault or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.