+ Reply to Thread
Results 1 to 4 of 4

Copying data from one sheet to other in the same workbook is taking too long time

  1. #1
    Registered User
    Join Date
    03-04-2021
    Location
    India
    MS-Off Ver
    2016
    Posts
    31

    Copying data from one sheet to other in the same workbook is taking too long time

    Hi All,
    I want to copy the data (EPI Unit Price, Material Sales Status and Product Code) from the EPI_GP sheet to the Price_List sheet for the matching EPI Product Numbers in Price_List on a Apply Unit Price to PB button click.

    After copying I need to replace the Material Sales Status code in Price_List with Name from Material_Status_Code for the matching codes.

    The code is also there in the attached example.
    It is working fine, but taking tooo longer time more than 15min and sometimes going into No Responding.

    Please help me to optimize the code for this purpose in a simpler way without impacting the performance.

    In real time will have thousands of rows in Price_List and EPI_List, where Price_List have more formula based columns.
    As for example I just uploaded some sample data.

    Please please please help me .... as this is is stopping to get the approval on the work done.

    Thanks in advance.


    Below is the code for reference.
    Set DictData = CreateObject("Scripting.Dictionary")
    'Iterator Worksheet 1, is the counter for the ws1 column
    Dim iWS1 As Integer
    'Iterator Worksheet 2, is the counter for the ws2 column
    Dim iWS2 As Integer
    'Maximal Row Count, need to be extend when new rows are added
    Dim MaxRows As Integer
    'valueHolder, is the holder for the orginal value, the orginal value might be replaced on the sheet
    Dim valueHolder As Variant
    'Worksheet1
    Dim ws1 As Worksheet
    'Worlsheet2
    Dim ws2 As Worksheet
    'Call UnprotectPriceList
    Set ws1 = ThisWorkbook.Worksheets("Price_List")
    Set ws2 = ThisWorkbook.Worksheets("EPI_GP")

    Application.Calculation = xlCalculationManual
    lastRow = ws2.Cells(Rows.count, "D").End(xlUp).Row
    myArr = ws2.Range("D5:P" & lastRow)
    firstEmptyRow = ws1.Cells(ws1.Rows.count, "D").End(xlUp).Row
    If firstEmptyRow <= 5 Then
    firstEmptyRow = 6
    End If
    'ThisWorkbook.Worksheets("Price_List").Activate

    'Set iWS1 to the first row
    iWS1 = 6
    'Get MaxRows
    MaxRows = ws1.Cells(Rows.count, 4).End(xlUp).Row

    'Loop through the Rows on WS1 setting switch to 0 and store the value from the ws1 row in the holder
    While iWS1 <= MaxRows
    valueHolder = ws1.Cells(iWS1, 11).Value

    ''Loop through the Rows on WS2, searching for a value that match with the value from ws1
    'For iWS2 = 5 To ws2.Cells(Rows.count, 5).End(xlUp).Row
    ' 'When it matches, then look if there was already a match with the value, if not replace it on the ws1 and increase the sNr to 1
    ' If valueHolder = ws2.Cells(iWS2, 4).Value Then
    ' ws1.Cells(iWS1, 15).Value = ws2.Cells(iWS2, 9).Value
    ' ws1.Cells(iWS1, 19).Value = ws2.Cells(iWS2, 16).Value
    ' ws1.Cells(iWS1, 33).Value = ws2.Cells(iWS2, 6).Value
    ' End If
    'Next iWS2

    For i = 1 To UBound(myArr)
    ' 'When it matches, then look if there was already a match with the value, if not replace it on the ws1 and increase the sNr to 1
    If valueHolder <> "" Then
    If valueHolder = myArr(i, 1) Or valueHolder = Replace(myArr(i, 1), " ", "") Then
    ws1.Cells(iWS1, 15).Value = myArr(i, 6)
    ws1.Cells(iWS1, 19).Value = myArr(i, 13)
    ws1.Cells(iWS1, 33).Value = myArr(i, 3)
    End If
    End If
    Next
    iWS1 = iWS1 + 1
    Wend
    Attached Files Attached Files
    Last edited by Saritha123; 07-01-2021 at 10:59 AM.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Copying data from one sheet to other in the same workbook is taking too long time

    Try:
    Please Login or Register  to view this content.
    Last edited by Mumps1; 07-02-2021 at 01:01 PM.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    03-04-2021
    Location
    India
    MS-Off Ver
    2016
    Posts
    31

    Re: Copying data from one sheet to other in the same workbook is taking too long time

    Thanks, this solves the issue.

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Copying data from one sheet to other in the same workbook is taking too long time

    You are very welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 19
    Last Post: 08-18-2021, 11:23 PM
  2. Macro taking a long time to run
    By ghostly1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-28-2018, 09:22 AM
  3. [SOLVED] code taking a long time to execute, why?
    By kevinu in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-09-2018, 03:53 PM
  4. [SOLVED] Copying Spreadsheet taking extremely long time
    By mgs73 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-17-2014, 12:45 AM
  5. Taking non uniform data from one sheet and copying and organizing it into another sheet
    By worldrenowned in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-08-2012, 03:16 AM
  6. Better way to transfer data my way taking a long time
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-06-2011, 06:03 AM
  7. Macro taking too long time to run
    By sharmanjali87 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-02-2010, 07:08 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1