Closed Thread
Results 1 to 2 of 2

Method find & past or replace between two sheets

Hybrid View

teixeire Method find & past or replace... 04-17-2020, 10:50 AM
Pepe Le Mokko Re: Method find & past or... 04-17-2020, 11:08 AM
  1. #1
    Registered User
    Join Date
    02-22-2016
    Location
    Brazil
    MS-Off Ver
    2010
    Posts
    9

    Lightbulb Method find & past or replace between two sheets

    Hello world.

    I have written a VBA code to find a value in one sheet, and if match, just copy the entire row.. OK, it is not only it, let me explain how it works and the problem I am facing:

    First sheet, called "DATA";
    Second sheet, called "WEEK UPDATE"

    1 - The person paste a pre select data in sheet "WEEK UPDATE", then push the botton to check if the value existing in its sheet, exists in the sheet "DATA";

    IF YES, then the row from A to AJ ("week update") is overwritten in sheet "data" in the same colluns
    IF NOT, then the row from A to AJ ("week update") is PASTED in sheet "data" in the same colluns

    2 - The system check if the data in sheet "data", do not exist in sheet "week update", so put a value in collum AN as "Historic"

    IF the collunm is already as "Historic", and system find the value from "Data" in "week update", then the value "historic" is overwritten as "";

    .. NOW MY PROBLEM...

    It works very well, but with a small quantity of lines..
    I am using 50K lines in "week update" and ~40K in "data", and then the macro does not work

    any help, PLEASE ?



    follow the code:


    Sub Preencher_dados()
    
        Application.ScreenUpdating = False
        Worksheets("Data").Unprotect Password:="Henkel2020"
        Worksheets("Week Update").Unprotect Password:="Henkel2020"
        
        Sheets("Data").Columns("AP").EntireColumn.Hidden = False
        Sheets("Week Update").Columns("AK").EntireColumn.Hidden = False
        
        linha = 3
        contagem = 0
        ultima_linha1 = Sheets("Data").Range("C80000").End(xlUp).Row
        ultima_linha2 = Sheets("Week Update").Range("C80000").End(xlUp).Row
        If ultima_linha2 <= 2 Then MsgBox "Não existem novos dados a serem transferidos.", vbExclamation: GoTo Final
        
        
        'i = 3 'concatena coluna H e I da planilha Data
        'Do While i <= ultima_linha1
        '    Sheets("Data").Cells(i, "AP") = CStr(Sheets("Data").Cells(i, "H") & Sheets("Data").Cells(i, "I"))
        '    i = i + 1
        'Loop
        
        'i = 3 'concatena coluna H e I da planilha Week Update
        'Do While i <= ultima_linha2
        '    Sheets("Week Update").Cells(i, "AK") = CStr(Sheets("Week Update").Cells(i, "H") & Sheets("Week Update").Cells(i, "I"))
        '    i = i + 1
        'Loop
        
        'verificar adição de novas linhas (Secundária busca na primária)
        
        linha = 3
        texto = "Existem materiais que necessitam de revisão na(s) linha(s): "
    
         Do While Sheets("Data").Cells(linha, "C") <> Empty
            Var3 = Application.Match(Sheets("Data").Cells(linha, "AP").Value, Sheets("Week Update").Columns(37), *0)
            
            If WorksheetFunction.IsError(Var3) Then 'caso 3: existe uma linha na planilha primária que foi deletada da semana atual
                linha_apagada = linha
                Sheets("Data").Cells(linha, "AN") = "Historic"
            End If
            If Not WorksheetFunction.IsError(Var3) And Sheets("Data").Cells(linha, "AN") = "Historic" Then 'caso 3: existe uma linha antes deletada que voltou semana atual
                contagem = 1
                texto = texto & vbCr & linha & ";"
                Sheets("Data").Cells(linha, "AN") = Empty
            End If
            linha = linha + 1
            
        Loop
        
        
        Do While Sheets("Week Update").Cells(linha, "C") <> Empty
            Var1 = Application.Match(Sheets("Week Update").Cells(linha, "AK").Value, Sheets("Data").Columns(42), *0)
            
            If WorksheetFunction.IsError(Var1) Then 'caso 1: existe uma nova linha na semana atual
                Sheets("Week Update").Cells(linha, 1).Resize(1, 36).Copy Destination:=Sheets("Data").Range("A80000").End(xlUp).Offset(1, 0)
            End If
            
            
            If Not WorksheetFunction.IsError(Var1) Then 'caso 2: não existe uma nova linha na semana atual -> subscrever
                linha_sub = Sheets("Data").Columns(42).Find(Sheets("Week Update").Cells(linha, "AK"), LookIn:=xlValues).Row
                Sheets("Week Update").Cells(linha, 1).Resize(1, 36).Copy Destination:=Sheets("Data").Cells(linha_sub, 1)
            End If
            linha = linha + 1
        Loop
        
        'verificar exclusão de linhas (primária busca na secundária)
        'i = 3 'concatena coluna H e I da planilha Data
        'ultima_linha1 = Sheets("Data").Range("A1048576").End(xlUp).Row
        'Do While i <= ultima_linha1
        '    Sheets("Data").Cells(i, "AP") = CStr(Sheets("Data").Cells(i, "H") & Sheets("Data").Cells(i, "I"))
        '    i = i + 1
        'Loop
        
        
        
        Application.ScreenUpdating = True
        
        If contagem = 1 Then MsgBox texto, vbExclamation
        
        
    Final:
        
        Sheets("Week Update").Rows("4:80000").Delete Shift:=xlUp
        Sheets("Week Update").Range("A3:AJ3").ClearContents
        
        Sheets("Data").Columns("AP").EntireColumn.Hidden = True
        Sheets("Week Update").Columns("AK").EntireColumn.Hidden = True
        Sheets("Data").Select
        Worksheets("Data").Protect Password:="Henkel2020", DrawingObjects:=True, Contents:=True, Scenarios:=True _
            , AllowFiltering:=True
            
        Worksheets("Week Update").Protect Password:="Henkel2020"
        Application.ScreenUpdating = True
    
    End Sub

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2504
    Posts
    13,631

    Re: Method find & past or replace between two sheets

    Administrative Note:

    Welcome to the forum.

    Unfortunately, this is a duplicate thread, and you are allowed only ONE thread per issue here.

    Please see Forum Rule #5 about thread duplication.

    I am closing this thread, but you may continue here in the original thread: https://www.excelforum.com/excel-pro...ml#post5315318

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Find and replace in several (not all) sheets
    By blackberry2012 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-25-2019, 11:49 AM
  2. Find & Replace on Workbook Open - Error Method 'Cells' of object'_Global' failed
    By goomblar in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-13-2015, 09:41 AM
  3. VBA How to find and replace all values over 100% with 100% in all sheets
    By XLOpenUse in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-19-2014, 12:27 AM
  4. [SOLVED] Find & Replace All Sheets Using VBA
    By tmontg2 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-28-2012, 04:06 PM
  5. Find and replace on all sheets
    By Cornwell in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-22-2010, 10:41 AM
  6. Replace method - cannot find any data to replace
    By Mike in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-06-2006, 04:00 PM
  7. VBA in Microsoft Excel: Find & Replace method macro across multiple files
    By Pedro123 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-07-2005, 10:48 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