Hello,
I am trying to figure out this problem.
Basically I have 2 sheets with identical purpose - to reflect the stock.
The old sheet was messy and not sorted, no constant locations, duplicate locations, however I know that newer entries were added to the bottom.
So each location has 3 slots, like it is supposed to be, in the new sheet.
There are cases where, in the old sheet, you have 1 entry per location, no entries at all, or more than 3 entries.
What I need to achieve:
-Find last matching row in old sheet, compared to new sheet, column A.
-Copy over the last matching row from old data, to first matching row in the new sheet.
-Repeat until no more matches found.
What I've got so far:
It finds the last matching row in old data, but copies over only one match, and not in the first matching row into new sheet.
Example, desired result in column C:
Sheet "Main" (new) - this is where i would need excel to paste my values to
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]LOCATION[/TD]
[TD]DESCRIPTION[/TD]
[TD]DESIRED
[/TD]
[/TR]
[TR]
[TD]100A
[/TD]
[TD][/TD]
[TD]<- Data!B2[/TD]
[/TR]
[TR]
[TD]100B[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]100C[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]101A[/TD]
[TD][/TD]
[TD]<- Data!B7[/TD]
[/TR]
[TR]
[TD]101B[/TD]
[TD][/TD]
[TD]<- Data!B6[/TD]
[/TR]
[TR]
[TD]101C[/TD]
[TD][/TD]
[TD]<- Data!B5[/TD]
[/TR]
[TR]
[TD]102A[/TD]
[TD][/TD]
[TD]<- Data!B10[/TD]
[/TR]
[TR]
[TD]102B[/TD]
[TD][/TD]
[TD]<- Data!B9[/TD]
[/TR]
[TR]
[TD]102C[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Sheet "Data" (old) - this is where i would need excel to copy my values from
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]LOCATION[/TD]
[TD]DESCRIPTION[/TD]
[TD]<- cell[/TD]
[/TR]
[TR]
[TD]100[/TD]
[TD][TABLE="width: 186"]
<tbody>[TR]
[TD="class: xl65, width: 186"]packing supplies[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]b2[/TD]
[/TR]
[TR]
[TD]101[/TD]
[TD][TABLE="width: 186"]
<tbody>[TR]
[TD="class: xl65, width: 186"]IT hardware[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]b3[/TD]
[/TR]
[TR]
[TD]101[/TD]
[TD][TABLE="width: 186"]
<tbody>[TR]
[TD="class: xl65, width: 186"]medical supplies[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]b4[/TD]
[/TR]
[TR]
[TD]101[/TD]
[TD][TABLE="width: 186"]
<tbody>[TR]
[TD="class: xl65, width: 186"]medical supplies[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]b5[/TD]
[/TR]
[TR]
[TD]101[/TD]
[TD][TABLE="width: 186"]
<tbody>[TR]
[TD="class: xl65, width: 186"]medical supplies[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]b6[/TD]
[/TR]
[TR]
[TD]101[/TD]
[TD][TABLE="width: 186"]
<tbody>[TR]
[TD="class: xl65, width: 186"]furniture[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]b7[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]b8[/TD]
[/TR]
[TR]
[TD]102[/TD]
[TD][TABLE="width: 186"]
<tbody>[TR]
[TD="class: xl65, width: 186"]archive[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]b9[/TD]
[/TR]
[TR]
[TD]102[/TD]
[TD][TABLE="width: 186"]
<tbody>[TR]
[TD="class: xl65, width: 186"]metal bars[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]b10[/TD]
[/TR]
</tbody>[/TABLE]
So the end result would look like this:
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]LOCATION[/TD]
[TD]DESCRIPTION[/TD]
[/TR]
[TR]
[TD]100A[/TD]
[TD]packing supplies[/TD]
[/TR]
[TR]
[TD]100B[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]100C[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]101A[/TD]
[TD][TABLE="width: 186"]
<tbody>[TR]
[TD="class: xl65, width: 186"]furniture[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]101B[/TD]
[TD]medical supplies[/TD]
[/TR]
[TR]
[TD]101C[/TD]
[TD]medical supplies[/TD]
[/TR]
[TR]
[TD]102A[/TD]
[TD]metal bars[/TD]
[/TR]
[TR]
[TD]102B[/TD]
[TD]archive[/TD]
[/TR]
[TR]
[TD]102C[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Any help appreciated.
Thanks,
Matt.
I am trying to figure out this problem.
Basically I have 2 sheets with identical purpose - to reflect the stock.
The old sheet was messy and not sorted, no constant locations, duplicate locations, however I know that newer entries were added to the bottom.
So each location has 3 slots, like it is supposed to be, in the new sheet.
There are cases where, in the old sheet, you have 1 entry per location, no entries at all, or more than 3 entries.
What I need to achieve:
-Find last matching row in old sheet, compared to new sheet, column A.
-Copy over the last matching row from old data, to first matching row in the new sheet.
-Repeat until no more matches found.
What I've got so far:
Code:
Sub transfer()
Dim sh1 As Worksheet, sh2 As Worksheet, rng1 As Range, rng2 As Range
Set sh1 = Sheets("Main")
Set sh2 = Sheets("Data")
For Each rng1 In sh2.Range("A2", sh2.Cells(Rows.Count, 2).End(xlUp))
Set rng2 = sh1.Range("A2:A10").Find(rng1.Value, , xlValues, xlWhole)
If Not rng2 Is Nothing Then
rng2.Offset(, 1) = rng1.Offset(, 1).Value
End If
Next
End Sub
It finds the last matching row in old data, but copies over only one match, and not in the first matching row into new sheet.
Example, desired result in column C:
Sheet "Main" (new) - this is where i would need excel to paste my values to
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]LOCATION[/TD]
[TD]DESCRIPTION[/TD]
[TD]DESIRED
[/TD]
[/TR]
[TR]
[TD]100A
[/TD]
[TD][/TD]
[TD]<- Data!B2[/TD]
[/TR]
[TR]
[TD]100B[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]100C[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]101A[/TD]
[TD][/TD]
[TD]<- Data!B7[/TD]
[/TR]
[TR]
[TD]101B[/TD]
[TD][/TD]
[TD]<- Data!B6[/TD]
[/TR]
[TR]
[TD]101C[/TD]
[TD][/TD]
[TD]<- Data!B5[/TD]
[/TR]
[TR]
[TD]102A[/TD]
[TD][/TD]
[TD]<- Data!B10[/TD]
[/TR]
[TR]
[TD]102B[/TD]
[TD][/TD]
[TD]<- Data!B9[/TD]
[/TR]
[TR]
[TD]102C[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Sheet "Data" (old) - this is where i would need excel to copy my values from
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]LOCATION[/TD]
[TD]DESCRIPTION[/TD]
[TD]<- cell[/TD]
[/TR]
[TR]
[TD]100[/TD]
[TD][TABLE="width: 186"]
<tbody>[TR]
[TD="class: xl65, width: 186"]packing supplies[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]b2[/TD]
[/TR]
[TR]
[TD]101[/TD]
[TD][TABLE="width: 186"]
<tbody>[TR]
[TD="class: xl65, width: 186"]IT hardware[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]b3[/TD]
[/TR]
[TR]
[TD]101[/TD]
[TD][TABLE="width: 186"]
<tbody>[TR]
[TD="class: xl65, width: 186"]medical supplies[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]b4[/TD]
[/TR]
[TR]
[TD]101[/TD]
[TD][TABLE="width: 186"]
<tbody>[TR]
[TD="class: xl65, width: 186"]medical supplies[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]b5[/TD]
[/TR]
[TR]
[TD]101[/TD]
[TD][TABLE="width: 186"]
<tbody>[TR]
[TD="class: xl65, width: 186"]medical supplies[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]b6[/TD]
[/TR]
[TR]
[TD]101[/TD]
[TD][TABLE="width: 186"]
<tbody>[TR]
[TD="class: xl65, width: 186"]furniture[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]b7[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]b8[/TD]
[/TR]
[TR]
[TD]102[/TD]
[TD][TABLE="width: 186"]
<tbody>[TR]
[TD="class: xl65, width: 186"]archive[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]b9[/TD]
[/TR]
[TR]
[TD]102[/TD]
[TD][TABLE="width: 186"]
<tbody>[TR]
[TD="class: xl65, width: 186"]metal bars[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]b10[/TD]
[/TR]
</tbody>[/TABLE]
So the end result would look like this:
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]LOCATION[/TD]
[TD]DESCRIPTION[/TD]
[/TR]
[TR]
[TD]100A[/TD]
[TD]packing supplies[/TD]
[/TR]
[TR]
[TD]100B[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]100C[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]101A[/TD]
[TD][TABLE="width: 186"]
<tbody>[TR]
[TD="class: xl65, width: 186"]furniture[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]101B[/TD]
[TD]medical supplies[/TD]
[/TR]
[TR]
[TD]101C[/TD]
[TD]medical supplies[/TD]
[/TR]
[TR]
[TD]102A[/TD]
[TD]metal bars[/TD]
[/TR]
[TR]
[TD]102B[/TD]
[TD]archive[/TD]
[/TR]
[TR]
[TD]102C[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Any help appreciated.
Thanks,
Matt.