VBA data

hassansabbagh

New Member
Joined
Aug 25, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hello there'
I have four cells (A,B,C, and D), (A )contain a date and time of the day, (B,C, and D) contain data changing according to the day & time in A say the Temperature for example.
I need VBA code to copy B,C,D in sheet 1 and paste value in sheet sheet2 if (A), witch the day & time in sheet 2 match (A) in sheet 1. to record the data permanently so will not change when the original data in sheet1 changes with date & time.
1/09/2022 0:00​
20​
15​
10​

I appreciate your help.
Thank you.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Here VBA solution.
If you are new VBA user, try following steps
- Alt-F11 to open VBA window
- Insert/Module
- Paste below code into
- Hit F5 (or press play button) to run

VBA Code:
Option Explicit
Sub Looking()
Dim lr&, i&, j&, DataR As Range
With Sheets("Sheet1")
    lr = .Cells(Rows.Count, "A").End(xlUp).Row
    Set DataR = .Range("A1:D" & lr)
End With
With Sheets("Sheet2")
    For i = 1 To .Cells(Rows.Count, "A").End(xlUp).Row
        For j = 2 To 4
            With Cells(i, j)
                .Formula = "=IFERROR(VLOOKUP(" & Cells(i, 1).Address(0, 0) & ", Sheet1!A1:D" & lr & " ," & j & ",0),"""")"
                .Value = .Value
            End With
        Next
    Next
End With
End Sub
 
Upvote 0
Thank you very much,
It worked perfectly well.
I am grateful.

Kind regards.
Hassan
 
Upvote 0

Forum statistics

Threads
1,214,830
Messages
6,121,839
Members
449,051
Latest member
excelquestion515

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