find unique values in a workbook and replace their rows with the same rows values from another workbook

ProT

New Member
Joined
Feb 22, 2022
Messages
1
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
  2. MacOS
  3. Mobile
Hello, I am new to vba and I want to create a proxy for missing data in my workbook, so I would like to use the data from the previous date's workbook. I need to find the same names in column G of the previous date workbook copy their row from column D and paste it in my current workbook.
I am able to create a unique names array but not able to create the for loops and the if conditions. The unique array is created by the missing values.
The structure in both workbooks is the same but I do not need to copy-paste the first four columns. Below you can find what I have done so far.

VBA Code:
Sub unique()

Dim unique As Variant
Dim Fname As String


unique = WorksheetFunction.unique(Worksheets(2).Range("G:G"))

dat = Worksheets("Summary").Range("c3")

tempDate = DateAdd("d", -1, dat)         'Today's date - 1
While Weekday(tempDate) = 1 Or Weekday(tempDate) = 7
'If tempDate is a Sunday or a Saturday, keep on subtracting one day until we get a weekday
    tempDate = DateAdd("d", -1, tempDate)
   Wend

Fname = "path?"  & ".xlsm"


Set wb2 = Workbooks.Open(Fname)
Set col2 = wb2.Sheets("Summary").Range("G:G")

' Here is what I should figure out
For Each cell In col2

'  ......................
    End If
    
   Next cell
      wb2.Close SaveChanges:=False

End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,022
Latest member
RobertV1609

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
Back
Top