Need assistance with code issue??

M

Mekinnik

Is it possible and can one of you guru's help me with the creation of what I
am calling a double ended search. There are two parts to the search I am try
to accomplish. All this happens on a form when the user clicks the 'GO'
button.

#1)I want to use what the user selects in combobox 1 as my first searh
criteria to match the left 2 character of column 'M' of worksheet 1 and
return all the data from all the matching rows to the corresponding
columns/rows on worksheet 2.

#2)This is the double ended search. I would then like the same search (if
possible) to search within the just copied data column 'F' and find only the
first instance of a name and use it as the criteria for the second search (so
if I have 100 rows of data and 10 different names, it will search for those
10 name and update all 100 rows) to search worksheet three column 'A' and
then return the data from columns 'A' and 'F' to worksheet 2 column 'F',
however the data needs to be stacked in the cells of column 'F' worksheet 2.


I do already have some code for copying the data over I just need help in
writing the code for the search part of it.

I have tried to explain what it is I am trying to do, but if more info is
needed just let me know.
 
J

Joel

try this code

Sub movedata()

lookupdata = Sheets("Sheet1").ComboBox1.Text
With Sheets("Sheet3")
Sh3LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
End With
With Sheets("Sheet1")
Sh1LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
For Sh1RowCount = 1 To Sh1LastRow
If lookupdata = .Range("M" & Sh1RowCount) Then
.Rows(Sh1RowCount).Copy _
Destination:=Sheets("Sheet2").Rows(Sh1RowCount)
End If
Next Sh1RowCount
End With

With Sheets("Sheet2")
Sh2LastRow = .Cells(Rows.Count, "F").End(xlUp).Row
For Sh2Rowcount = 1 To Sh2LastRow
If .Range("F" & Sh2Rowcount) <> "" Then
MyName = .Range("F" & Sh2Rowcount)
'check if first instance
Set c = .Columns("F:F").Find(what:=MyName, _
LookIn:=xlValues)

If c.Row = Sh2Rowcount Then 'if equal then 1st time
With Sheets("Sheet3")
For Sh3RowCount = 1 To Sh3LastRow
If .Range("A" & Sh3RowCount) = MyName Then
'copy sheet 3 data to sheet 2
End If
Next Sh3RowCount
End With
End If
End If
Next Sh2Rowcount
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top