VBA to compare a range of values against another in different sheets

omninoob

New Member
Joined
Dec 23, 2018
Messages
3
Hi everyone! Am new here and would appreciate some help.

I have 2 sheets (Sheet 1 & Sheet 2) and would like to populate a portion of Sheet 2 with just 6 columns from a whole bunch of data I am updating manually everyday in Sheet 1 with a click of a button. However, there are some information that I would like to edit in the populated section of sheet 2 and would not want it to be updated every time I click it.

The only data that is constant that would not need changing is Column 'V' in Sheet 2. So I have tried various methods of using 'For - Each' cell in column V in Sheet 2 comparing to the its original entire range in column E in Sheet 1. If it matches, then do not initiate this copy and paste macro for that row. So far I have been unsuccessful as I am unable to reference Sheet 2 in every For - Each code I tried.

This is the only thing that works currently. The pasting starts from row 2 as the first row is a header.
With Sheet1

' 1st Column in Sheet (Date)
.Range("C5", .Cells(Rows.Count, "C").End(xlUp)).Copy Sheet2.Range("U2")


' 2nd Column in Sheet 2
.Range("E5", .Cells(Rows.Count, "E").End(xlUp)).Copy Sheet2.Range("V2")

' 3rd Column in Sheet 2
.Range("AF5", .Cells(Rows.Count, "AF").End(xlUp)).Copy Sheet2.Range("W2")

' 4th Column in Sheet 2
.Range("AG5", .Cells(Rows.Count, "AG").End(xlUp)).Copy Sheet2.Range("X2")

' 5th Number Column in Sheet 2
.Range("AH5", .Cells(Rows.Count, "AH").End(xlUp)).Copy Sheet2.Range("Y2")

' 6th Column in Sheet 2
.Range("AU5", .Cells(Rows.Count, "AU").End(xlUp)).Copy Sheet2.Range("Z2")

' Data in Sheet 2 without format
Sheet2.Range("U2:Z1000").ClearFormats
Sheet2.Range("U2:U1000").NumberFormat = "mm/dd/yyyy"
Sheet2.Range("U2:Z1000").Borders.LineStyle = xlNone
Sheet2.Range("U2:Z1000").HorizontalAlignment = xlCenter

End With

Thank you!
 

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.
In sheet 2 in cell V2, do you have the same data on sheet 1 in cell E5?
Then I must compare V2 with E5, V3 with E6, V4 with E7, and so on.
If V3 is different from E6, then copy the data from row 6 of sheet 1 in row 3 of sheet 2?
 
Upvote 0

Forum statistics

Threads
1,223,891
Messages
6,175,229
Members
452,621
Latest member
Laura_PinksBTHFT

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