If not Find Replace Value

TEIXEIRE

New Member
Joined
Apr 17, 2020
Messages
27
Office Version
  1. 365
Platform
  1. Windows
If have the below code in the attached file. The file is updated weekly, so CW (current week) will has the data of W-1 plus CW (current week) to be updated, and the code needs to cross check if the data already exists or not. The code is trigger by the existing butonn in tab "Week Update". There are aproximately 4 checks, but only one is not working, which is:

  • If the line already exist in tab "Data" (using the collunm AV as key to check), but do not exist in the data of CW (current week) in tab "Week Update"(using the collunm AK as key to check), then the correspondent line in collunm AT in tab "Data", will switch to "Historical";
@Fluff

Whats already working?

  1. New lines are added on tab "data" from "Week Update", if do not exists yet, and the collunm AT mus be [blank]; OK
  2. If an existing line exists on "Data" and collunm AT is "Historical", and the it also exists on CW (current week) in tab "Week Update", then switch from "Historical" to ""; OK

Click here to access the file

VBA Code:
Sub DataUpdate()
   Dim Dary As Variant, Hary As Variant, Uary As Variant, Nary As Variant, Nhary As Variant
   Dim i As Long, c As Long, UsdRws As Long, nr As Long
   Dim Dic As Object
   
   Application.ScreenUpdating = False
   Worksheets("Data").Unprotect Password:="Henkel2020"
   

   Set Dic = CreateObject("scripting.dictionary")
   
   With Sheets("Week Update")
      UsdRws = .Range("C" & Rows.Count).End(xlUp).Row
      Uary = .Range("A3:AK" & UsdRws)
   End With
   
   With Sheets("Data")
      UsdRws = .Range("C" & Rows.Count).End(xlUp).Row
      Dary = .Range("AV3:AV" & UsdRws).Value2
      Hary = .Range("AT3:AT" & UsdRws).Value2
   End With
   
   For i = 1 To UBound(Dary)
      Dic(Dary(i, 1)) = i
   Next i
   
   With Sheets("Data")
      Dary = .Range("A3:AJ" & UsdRws).Value2
   End With
   
   ReDim Nary(1 To UBound(Uary), 1 To 36)
   For i = 1 To UBound(Uary)
      If Dic.Exists(Uary(i, 37)) Then
         For c = 1 To 36
            Dary(Dic(Uary(i, 37)), c) = Uary(i, c)
         Next c
         If Hary(Dic(Uary(i, 37)), 1) = "Historical" Then Hary(Dic(Uary(i, 37)), 1) = ""
      Else
         nr = nr + 1
         For c = 1 To 36
            Nary(nr, c) = Uary(i, c)
         Next c
         Hary(i, 1) = "Historical"
      End If
   Next i
   
   With Sheets("Data")
      .Range("A3:AJ" & UsdRws).Value = Dary
      .Range("AT3:AT" & UsdRws).Value = Hary
      If nr > 0 Then
         .Range("A" & UsdRws + 1).Resize(nr, 36).Value = Nary
         .Range("AT" & UsdRws + 1).Resize(nr, 1).Value = Nhary
      End If
   End With
  
  Sheets("Week Update").ListObjects(1).DataBodyRange.EntireRow.Delete
  Sheets("Week Update").Range("Update[Document NumberDocument Line Number]") = "=[@[Document Number]]&[@[Document Line Number]]"
  
  Worksheets("Data").Protect Password:="Henkel2020", DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFiltering:=True, UserInterfaceOnly:=True

  Worksheets("Data").EnableOutlining = True
  
  Application.ScreenUpdating = True
    
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

TEIXEIRE

New Member
Joined
Apr 17, 2020
Messages
27
Office Version
  1. 365
Platform
  1. Windows
as additional information, the file is set up to check if the macro works.

the scenario which is not working and I am asking for help, is after the macro runs, in the tab "Data", for the values below (to be checked in collunm AV), must be with value "Historical" in collunm AT;


40811073610
40820554010
40823667510

As IS
1609957972187.png

To Be

In Correction, "Historical"
(just because there are not these values present in "Week Update" before the macro runs)
 

Watch MrExcel Video

Forum statistics

Threads
1,129,685
Messages
5,637,808
Members
416,983
Latest member
LessThanAverageUser

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top