Hi guys,
I am new to this forum so I hope I am doing this correct.
I need some help. I am trying to make a VBA code to find duplicate number and use the last one in that column.
ie. I have columns "A", "B", "C", "D", "E", "F"
in Column "D" i have a lot number that is 11,101,102,103 etc There will be several 100s, serveal101s and so on. They will and should always be grouped together, so I just want to be able to typoe in a value into textbox1 and search for the last number in that group and return the infor from that row into the other textboxs. ie textbox2, textbox3 etc.
I hope I didn't make it to complicated. I searched for over a couple of weeks and could not find anything to this. I tried useing the Lastrow, xlPrevious, xlEnd. but I can't get it to work.
Any help would be greatly appreciated.
Private Sub CommandButton1_Click()Dim i As Long
Set obj = ThisWorkbook.Sheets("Sheet1")
With obj.UsedRange
Set c = .Find(TextBox1.Text) '.End(xlLast)
'For x = 1 To 2
Me("TextBox2") = obj.Cells(c.Row, 1).Value
Me("TextBox3") = obj.Cells(c.Row, 2).Value
Me("TextBox4") = obj.Cells(c.Row, 3).Value
Me("TextBox5") = obj.Cells(c.Row, 4).Value
Me("TextBox6") = obj.Cells(c.Row, 5).Value
Me("TextBox7") = obj.Cells(c.Row, 6).Value
'Next x
End With
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub CommandButton2_Click()
Me("TextBox1") = ""
Me("TextBox2") = ""
Me("TextBox3") = ""
Me("TextBox4") = ""
Me("TextBox5") = ""
Me("TextBox6") = ""
Me("TextBox7") = ""
End Sub
____________________________________________________________
[TABLE="width: 384"]
<colgroup><col width="64" span="6" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl63, width: 64"]#1[/TD]
[TD="class: xl63, width: 64"]#2[/TD]
[TD="class: xl63, width: 64"]#3[/TD]
[TD="class: xl63, width: 64"]#4[/TD]
[TD="class: xl63, width: 64"]#5[/TD]
[TD="class: xl63, width: 64"]#6[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]10[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]100[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]201[/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD="align: right"]10[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]100[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]202[/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD="align: right"]12[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]100[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]203[/TD]
[/TR]
[TR]
[TD="align: right"]4[/TD]
[TD="align: right"]13[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]100[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]204[/TD]
[/TR]
[TR]
[TD="align: right"]5[/TD]
[TD="align: right"]12[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]101[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]205[/TD]
[/TR]
[TR]
[TD="align: right"]6[/TD]
[TD="align: right"]15[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]101[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]206[/TD]
[/TR]
[TR]
[TD="align: right"]7[/TD]
[TD="align: right"]13[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]101[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]207[/TD]
[/TR]
[TR]
[TD="align: right"]8[/TD]
[TD="align: right"]16[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]101[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]208[/TD]
[/TR]
[TR]
[TD="align: right"]9[/TD]
[TD="align: right"]23[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]102[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]209[/TD]
[/TR]
[TR]
[TD="align: right"]10[/TD]
[TD="align: right"]25[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]102[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]210[/TD]
[/TR]
[TR]
[TD="align: right"]11[/TD]
[TD="align: right"]27[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]102[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]211[/TD]
[/TR]
[TR]
[TD="align: right"]12[/TD]
[TD="align: right"]23[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]102[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]212[/TD]
[/TR]
[TR]
[TD="align: right"]13[/TD]
[TD="align: right"]25[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]103[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]213[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]23[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]103[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]214[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]26[/TD]
[TD="class: xl65"]BB[/TD]
[TD="align: right"]103[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]215[/TD]
[/TR]
[TR]
[TD="align: right"]16[/TD]
[TD="align: right"]24[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]103[/TD]
[TD="class: xl64, align: right"]14-Jun[/TD]
[TD="align: right"]216[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]2[/TD]
[TD="class: xl65"]BB[/TD]
[TD="align: right"]104[/TD]
[TD="class: xl64, align: right"]14-Jun[/TD]
[TD="align: right"]217[/TD]
[/TR]
[TR]
[TD="align: right"]18[/TD]
[TD="align: right"]2[/TD]
[TD="class: xl65"]BB[/TD]
[TD="align: right"]104[/TD]
[TD="class: xl64, align: right"]14-Jun[/TD]
[TD="align: right"]218[/TD]
[/TR]
</tbody>[/TABLE]
I am new to this forum so I hope I am doing this correct.
I need some help. I am trying to make a VBA code to find duplicate number and use the last one in that column.
ie. I have columns "A", "B", "C", "D", "E", "F"
in Column "D" i have a lot number that is 11,101,102,103 etc There will be several 100s, serveal101s and so on. They will and should always be grouped together, so I just want to be able to typoe in a value into textbox1 and search for the last number in that group and return the infor from that row into the other textboxs. ie textbox2, textbox3 etc.
I hope I didn't make it to complicated. I searched for over a couple of weeks and could not find anything to this. I tried useing the Lastrow, xlPrevious, xlEnd. but I can't get it to work.
Any help would be greatly appreciated.
Private Sub CommandButton1_Click()Dim i As Long
Set obj = ThisWorkbook.Sheets("Sheet1")
With obj.UsedRange
Set c = .Find(TextBox1.Text) '.End(xlLast)
'For x = 1 To 2
Me("TextBox2") = obj.Cells(c.Row, 1).Value
Me("TextBox3") = obj.Cells(c.Row, 2).Value
Me("TextBox4") = obj.Cells(c.Row, 3).Value
Me("TextBox5") = obj.Cells(c.Row, 4).Value
Me("TextBox6") = obj.Cells(c.Row, 5).Value
Me("TextBox7") = obj.Cells(c.Row, 6).Value
'Next x
End With
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub CommandButton2_Click()
Me("TextBox1") = ""
Me("TextBox2") = ""
Me("TextBox3") = ""
Me("TextBox4") = ""
Me("TextBox5") = ""
Me("TextBox6") = ""
Me("TextBox7") = ""
End Sub
____________________________________________________________
[TABLE="width: 384"]
<colgroup><col width="64" span="6" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl63, width: 64"]#1[/TD]
[TD="class: xl63, width: 64"]#2[/TD]
[TD="class: xl63, width: 64"]#3[/TD]
[TD="class: xl63, width: 64"]#4[/TD]
[TD="class: xl63, width: 64"]#5[/TD]
[TD="class: xl63, width: 64"]#6[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]10[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]100[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]201[/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD="align: right"]10[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]100[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]202[/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD="align: right"]12[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]100[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]203[/TD]
[/TR]
[TR]
[TD="align: right"]4[/TD]
[TD="align: right"]13[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]100[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]204[/TD]
[/TR]
[TR]
[TD="align: right"]5[/TD]
[TD="align: right"]12[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]101[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]205[/TD]
[/TR]
[TR]
[TD="align: right"]6[/TD]
[TD="align: right"]15[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]101[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]206[/TD]
[/TR]
[TR]
[TD="align: right"]7[/TD]
[TD="align: right"]13[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]101[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]207[/TD]
[/TR]
[TR]
[TD="align: right"]8[/TD]
[TD="align: right"]16[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]101[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]208[/TD]
[/TR]
[TR]
[TD="align: right"]9[/TD]
[TD="align: right"]23[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]102[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]209[/TD]
[/TR]
[TR]
[TD="align: right"]10[/TD]
[TD="align: right"]25[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]102[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]210[/TD]
[/TR]
[TR]
[TD="align: right"]11[/TD]
[TD="align: right"]27[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]102[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]211[/TD]
[/TR]
[TR]
[TD="align: right"]12[/TD]
[TD="align: right"]23[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]102[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]212[/TD]
[/TR]
[TR]
[TD="align: right"]13[/TD]
[TD="align: right"]25[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]103[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]213[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]23[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]103[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]214[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]26[/TD]
[TD="class: xl65"]BB[/TD]
[TD="align: right"]103[/TD]
[TD="class: xl64, align: right"]12-Jun[/TD]
[TD="align: right"]215[/TD]
[/TR]
[TR]
[TD="align: right"]16[/TD]
[TD="align: right"]24[/TD]
[TD="class: xl65"]AA[/TD]
[TD="align: right"]103[/TD]
[TD="class: xl64, align: right"]14-Jun[/TD]
[TD="align: right"]216[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]2[/TD]
[TD="class: xl65"]BB[/TD]
[TD="align: right"]104[/TD]
[TD="class: xl64, align: right"]14-Jun[/TD]
[TD="align: right"]217[/TD]
[/TR]
[TR]
[TD="align: right"]18[/TD]
[TD="align: right"]2[/TD]
[TD="class: xl65"]BB[/TD]
[TD="align: right"]104[/TD]
[TD="class: xl64, align: right"]14-Jun[/TD]
[TD="align: right"]218[/TD]
[/TR]
</tbody>[/TABLE]