Macro for checking data in a cell against another cell andcopying/pasting data
Not sure I understood it completely, but I think this code should do what I managed to understand:
sub DataTransfer()
dim Month2 as Worksheets
dim Month1 as Worksheets
dim data as Worksheets
dim ColOfInterest(3) as Integer
dim dateHeader as Integer = 2 'Assuming your date is stored in
' row 2. Change to the row number of the date
set Month2 = Worksheets("May")
set Month1 = Worksheets("June")
set data = worksheets("data")
for i = 1 to 100
ColOfInterest(3) = i
for j = 1 to 100
if ( data.Cells(dateHeader, ColOfInterest(3)) = _
Month1.Cells(dateHeader,j) ) then ColOfInterest(1) = j
if ( data.Cells(dateHeader, ColOfInterest(3)) = _
Month2.Cells(dateHeader,j) ) then ColOfInterest(2) = j
next j
if j = 100 then goto skip_label
for j = 5 to 22
if ( Month2.Cells(j,ColOfInterest(2)) _
Month1.Cells(j,ColOfInterest(1)) ) then
data.Cells(j,ColOfInterest(3)) = _
Month1.Cells(j,ColOfInterest(1)) + Month2.Cells(j,ColOfInterest(2))
data.Cells(j,ColOfInterest(3)).font.color _
= RGB( 255, 0, 0 )
else
data.Cells(j,ColOfInterest(3)) = _
Month1.Cells(j,ColOfInterest(1))
end if
next j
skip_label:
next i
end sub
|