THRASHER69
Board Regular
- Joined
- Mar 29, 2012
- Messages
- 200
Hello,
I am having trouble figuring out how to fix this code and am hoping someone here can help me out. I have the code below to compare sh1 to sh2. The code works fine if my sheet has single rows that meet the criteria. If there is multiple rows that meet the criteria, it will skip over them. I'm not getting any kind of error. The code runs all the way through. It just skips the rows with multiple criteria. Below is the code and parts of each spreadsheet to look at. As you can see from the example below, the notes in red transfer from sh2 to sh1 just fine except for the rows that have 5/20/2014 in column A. It should insert a row after the last row of that date also and insert the note from sh2. I think it is in the part of the code I made red but I do not know how to fix it. Any help would be much appreciated.
sh1 after running the code:
[TABLE="width: 1199"]
<tbody>[TR]
[TD] 5/22/14[/TD]
[TD] 5/20/14[/TD]
[TD]29A14269[/TD]
[TD]3"8V PCSB W/1.5"COMP"G"CONE,HS[/TD]
[TD]0001462494[/TD]
[TD]71803[/TD]
[TD]4[/TD]
[TD]LUFKIN MIDDLE EAST - FREE ZONE[/TD]
[/TR]
[TR]
[TD="colspan: 8"]Credit Hold[/TD]
[/TR]
[TR]
[TD] 5/29/14[/TD]
[TD] 5/23/14[/TD]
[TD]21050116[/TD]
[TD]1.12"-1.5"T302 ROD ROT W/ BC26[/TD]
[TD]0001463802[/TD]
[TD]71803[/TD]
[TD]25[/TD]
[TD]LUFKIN MIDDLE EAST - FREE ZONE[/TD]
[/TR]
[TR]
[TD="colspan: 8"]Credit Hold[/TD]
[/TR]
[TR]
[TD] 5/30/14[/TD]
[TD] 3/27/14[/TD]
[TD]12049401[/TD]
[TD]5/8"-1"SET OF BUNA-N RAMS(2)[/TD]
[TD]0001457885[/TD]
[TD]T00103577[/TD]
[TD]36[/TD]
[TD]NATIONAL DRILLING SERVICES CO, LLC[/TD]
[/TR]
[TR]
[TD] 5/30/14[/TD]
[TD] 3/27/14[/TD]
[TD]12049402[/TD]
[TD]1.12" SET OF BUNA-N RAMS (2)[/TD]
[TD]0001457885[/TD]
[TD]T00103577[/TD]
[TD]32[/TD]
[TD]NATIONAL DRILLING SERVICES CO, LLC[/TD]
[/TR]
[TR]
[TD] 5/30/14[/TD]
[TD] 3/27/14[/TD]
[TD]12049403[/TD]
[TD]1.25" SET OF BUNA-N RAMS (2)[/TD]
[TD]0001457885[/TD]
[TD]T00103577[/TD]
[TD]12[/TD]
[TD]NATIONAL DRILLING SERVICES CO, LLC[/TD]
[/TR]
[TR]
[TD] 6/2/14[/TD]
[TD] 5/22/14[/TD]
[TD]21203006[/TD]
[TD]1.5"FIGURE 3 HINGE CLAMP[/TD]
[TD]0001463603[/TD]
[TD]71803[/TD]
[TD]150[/TD]
[TD]LUFKIN MIDDLE EAST - FREE ZONE[/TD]
[/TR]
[TR]
[TD="colspan: 8"]Credit Hold[/TD]
[/TR]
[TR]
[TD] 6/5/14[/TD]
[TD] 5/29/14[/TD]
[TD]37210305[/TD]
[TD]1"2000# 210 BV-1PC[/TD]
[TD]0001464300[/TD]
[TD]66602[/TD]
[TD]50[/TD]
[TD]KEN MILLER SUPPLY, INC[/TD]
[/TR]
[TR]
[TD="colspan: 8"]Due 6-2 EMC -> ABC
sh2 is the sheet it's getting the notes from:
[TABLE="width: 1024"]
<tbody>[TR]
[TD] 5/22/14[/TD]
[TD] 5/20/14[/TD]
[TD]29A14269[/TD]
[TD]3"8V PCSB W/1.5"COMP"G"CONE,HS[/TD]
[TD]0001462494[/TD]
[TD]71803[/TD]
[TD]4[/TD]
[TD]LUFKIN MIDDLE EAST - FREE ZONE[/TD]
[/TR]
[TR]
[TD="colspan: 8"]Credit Hold[/TD]
[/TR]
[TR]
[TD] 5/29/14[/TD]
[TD] 5/23/14[/TD]
[TD]21050116[/TD]
[TD]1.12"-1.5"T302 ROD ROT W/ BC26[/TD]
[TD]0001463802[/TD]
[TD]71803[/TD]
[TD]25[/TD]
[TD]LUFKIN MIDDLE EAST - FREE ZONE[/TD]
[/TR]
[TR]
[TD="colspan: 8"]Credit Hold[/TD]
[/TR]
[TR]
[TD] 5/30/14[/TD]
[TD] 3/27/14[/TD]
[TD]12049401[/TD]
[TD]5/8"-1"SET OF BUNA-N RAMS(2)[/TD]
[TD]0001457885[/TD]
[TD]T00103577[/TD]
[TD]36[/TD]
[TD]NATIONAL DRILLING SERVICES CO, LLC[/TD]
[/TR]
[TR]
[TD] 5/30/14[/TD]
[TD] 3/27/14[/TD]
[TD]12049402[/TD]
[TD]1.12" SET OF BUNA-N RAMS (2)[/TD]
[TD]0001457885[/TD]
[TD]T00103577[/TD]
[TD]32[/TD]
[TD]NATIONAL DRILLING SERVICES CO, LLC[/TD]
[/TR]
[TR]
[TD] 5/30/14[/TD]
[TD] 3/27/14[/TD]
[TD]12049403[/TD]
[TD]1.25" SET OF BUNA-N RAMS (2)[/TD]
[TD]0001457885[/TD]
[TD]T00103577[/TD]
[TD]12[/TD]
[TD]NATIONAL DRILLING SERVICES CO, LLC[/TD]
[/TR]
[TR]
[TD="colspan: 8"]Credit Hold[/TD]
[/TR]
[TR]
[TD] 6/2/14[/TD]
[TD] 5/22/14[/TD]
[TD]21203006[/TD]
[TD]1.5"FIGURE 3 HINGE CLAMP[/TD]
[TD]0001463603[/TD]
[TD]71803[/TD]
[TD]150[/TD]
[TD]LUFKIN MIDDLE EAST - FREE ZONE[/TD]
[/TR]
[TR]
[TD="colspan: 8"]Credit Hold[/TD]
[/TR]
[TR]
[TD] 6/5/14[/TD]
[TD] 5/29/14[/TD]
[TD]37210305[/TD]
[TD]1"2000# 210 BV-1PC[/TD]
[TD]0001464300[/TD]
[TD]66602[/TD]
[TD]50[/TD]
[TD]KEN MILLER SUPPLY, INC[/TD]
[/TR]
[TR]
[TD="colspan: 8"]Due 6-2 EMC -> ABC[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
I am having trouble figuring out how to fix this code and am hoping someone here can help me out. I have the code below to compare sh1 to sh2. The code works fine if my sheet has single rows that meet the criteria. If there is multiple rows that meet the criteria, it will skip over them. I'm not getting any kind of error. The code runs all the way through. It just skips the rows with multiple criteria. Below is the code and parts of each spreadsheet to look at. As you can see from the example below, the notes in red transfer from sh2 to sh1 just fine except for the rows that have 5/20/2014 in column A. It should insert a row after the last row of that date also and insert the note from sh2. I think it is in the part of the code I made red but I do not know how to fix it. Any help would be much appreciated.
Code:
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, rng As Range, c As Range, fLoc As RangeDim fAdr As String
Set sh1 = Sheets("Back Orders")
Set sh2 = Sheets("BO Save")
lr = sh1.Cells(Rows.Count, 5).End(xlUp).Row
Set rng = sh1.Range("E7:E" & lr)
For Each c In rng
Set fLoc = sh2.Range("E:E").Find(c.Value, , xlValues)
If Not fLoc Is Nothing Then
fAdr = fLoc.Address
Do
[COLOR=#ff0000]If Trim(c.Offset(0, -4).Value) = Trim(fLoc.Offset(0, -4).Value) Then
If fLoc.Offset(1, 0) = "" And fLoc.Offset(1, -4) <> "" Then
c.Offset(1, 0).EntireRow.Insert
fLoc.Offset(1, -4).Copy c.Offset(1, -4)
c.Offset(1, -4).Columns("A:J").Merge[/COLOR]
End If
Exit Do
End If
fLoc = sh2.Range("E:E").FindNext(fLoc)
Loop While fAdr <> fLoc.Address
End If
Next
sh1 after running the code:
[TABLE="width: 1199"]
<tbody>[TR]
[TD] 5/22/14[/TD]
[TD] 5/20/14[/TD]
[TD]29A14269[/TD]
[TD]3"8V PCSB W/1.5"COMP"G"CONE,HS[/TD]
[TD]0001462494[/TD]
[TD]71803[/TD]
[TD]4[/TD]
[TD]LUFKIN MIDDLE EAST - FREE ZONE[/TD]
[/TR]
[TR]
[TD="colspan: 8"]Credit Hold[/TD]
[/TR]
[TR]
[TD] 5/29/14[/TD]
[TD] 5/23/14[/TD]
[TD]21050116[/TD]
[TD]1.12"-1.5"T302 ROD ROT W/ BC26[/TD]
[TD]0001463802[/TD]
[TD]71803[/TD]
[TD]25[/TD]
[TD]LUFKIN MIDDLE EAST - FREE ZONE[/TD]
[/TR]
[TR]
[TD="colspan: 8"]Credit Hold[/TD]
[/TR]
[TR]
[TD] 5/30/14[/TD]
[TD] 3/27/14[/TD]
[TD]12049401[/TD]
[TD]5/8"-1"SET OF BUNA-N RAMS(2)[/TD]
[TD]0001457885[/TD]
[TD]T00103577[/TD]
[TD]36[/TD]
[TD]NATIONAL DRILLING SERVICES CO, LLC[/TD]
[/TR]
[TR]
[TD] 5/30/14[/TD]
[TD] 3/27/14[/TD]
[TD]12049402[/TD]
[TD]1.12" SET OF BUNA-N RAMS (2)[/TD]
[TD]0001457885[/TD]
[TD]T00103577[/TD]
[TD]32[/TD]
[TD]NATIONAL DRILLING SERVICES CO, LLC[/TD]
[/TR]
[TR]
[TD] 5/30/14[/TD]
[TD] 3/27/14[/TD]
[TD]12049403[/TD]
[TD]1.25" SET OF BUNA-N RAMS (2)[/TD]
[TD]0001457885[/TD]
[TD]T00103577[/TD]
[TD]12[/TD]
[TD]NATIONAL DRILLING SERVICES CO, LLC[/TD]
[/TR]
[TR]
[TD] 6/2/14[/TD]
[TD] 5/22/14[/TD]
[TD]21203006[/TD]
[TD]1.5"FIGURE 3 HINGE CLAMP[/TD]
[TD]0001463603[/TD]
[TD]71803[/TD]
[TD]150[/TD]
[TD]LUFKIN MIDDLE EAST - FREE ZONE[/TD]
[/TR]
[TR]
[TD="colspan: 8"]Credit Hold[/TD]
[/TR]
[TR]
[TD] 6/5/14[/TD]
[TD] 5/29/14[/TD]
[TD]37210305[/TD]
[TD]1"2000# 210 BV-1PC[/TD]
[TD]0001464300[/TD]
[TD]66602[/TD]
[TD]50[/TD]
[TD]KEN MILLER SUPPLY, INC[/TD]
[/TR]
[TR]
[TD="colspan: 8"]Due 6-2 EMC -> ABC
sh2 is the sheet it's getting the notes from:
[TABLE="width: 1024"]
<tbody>[TR]
[TD] 5/22/14[/TD]
[TD] 5/20/14[/TD]
[TD]29A14269[/TD]
[TD]3"8V PCSB W/1.5"COMP"G"CONE,HS[/TD]
[TD]0001462494[/TD]
[TD]71803[/TD]
[TD]4[/TD]
[TD]LUFKIN MIDDLE EAST - FREE ZONE[/TD]
[/TR]
[TR]
[TD="colspan: 8"]Credit Hold[/TD]
[/TR]
[TR]
[TD] 5/29/14[/TD]
[TD] 5/23/14[/TD]
[TD]21050116[/TD]
[TD]1.12"-1.5"T302 ROD ROT W/ BC26[/TD]
[TD]0001463802[/TD]
[TD]71803[/TD]
[TD]25[/TD]
[TD]LUFKIN MIDDLE EAST - FREE ZONE[/TD]
[/TR]
[TR]
[TD="colspan: 8"]Credit Hold[/TD]
[/TR]
[TR]
[TD] 5/30/14[/TD]
[TD] 3/27/14[/TD]
[TD]12049401[/TD]
[TD]5/8"-1"SET OF BUNA-N RAMS(2)[/TD]
[TD]0001457885[/TD]
[TD]T00103577[/TD]
[TD]36[/TD]
[TD]NATIONAL DRILLING SERVICES CO, LLC[/TD]
[/TR]
[TR]
[TD] 5/30/14[/TD]
[TD] 3/27/14[/TD]
[TD]12049402[/TD]
[TD]1.12" SET OF BUNA-N RAMS (2)[/TD]
[TD]0001457885[/TD]
[TD]T00103577[/TD]
[TD]32[/TD]
[TD]NATIONAL DRILLING SERVICES CO, LLC[/TD]
[/TR]
[TR]
[TD] 5/30/14[/TD]
[TD] 3/27/14[/TD]
[TD]12049403[/TD]
[TD]1.25" SET OF BUNA-N RAMS (2)[/TD]
[TD]0001457885[/TD]
[TD]T00103577[/TD]
[TD]12[/TD]
[TD]NATIONAL DRILLING SERVICES CO, LLC[/TD]
[/TR]
[TR]
[TD="colspan: 8"]Credit Hold[/TD]
[/TR]
[TR]
[TD] 6/2/14[/TD]
[TD] 5/22/14[/TD]
[TD]21203006[/TD]
[TD]1.5"FIGURE 3 HINGE CLAMP[/TD]
[TD]0001463603[/TD]
[TD]71803[/TD]
[TD]150[/TD]
[TD]LUFKIN MIDDLE EAST - FREE ZONE[/TD]
[/TR]
[TR]
[TD="colspan: 8"]Credit Hold[/TD]
[/TR]
[TR]
[TD] 6/5/14[/TD]
[TD] 5/29/14[/TD]
[TD]37210305[/TD]
[TD]1"2000# 210 BV-1PC[/TD]
[TD]0001464300[/TD]
[TD]66602[/TD]
[TD]50[/TD]
[TD]KEN MILLER SUPPLY, INC[/TD]
[/TR]
[TR]
[TD="colspan: 8"]Due 6-2 EMC -> ABC[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]