PDA

View Full Version : Search



thair younis
12-03-2011, 02:23 AM
Hi
How can i search in two columns (A and B)
thank you

Kenneth Hobs
12-03-2011, 08:16 PM
You need to be more specific.

thair younis
12-04-2011, 01:54 AM
Hi
First thank you Mr. Kenneth Hobs for reply me
Second this attached will clear to you


http://speedy.sh/HnZsd/New-Test.rar

Kenneth Hobs
12-04-2011, 02:20 AM
Attaching files off-forum is fine if the file size is too big. I am not a fan of RAR since most do not have it. If you must compress a file, use ZIP. Otherwise, just attach it without compression if small enough.

thair younis
12-04-2011, 04:16 AM
ok try this

Kenneth Hobs
12-04-2011, 06:27 AM
Sub FindIT()
Dim f As Range
Set f = Columns("A:B").Find("Hamour")
If Not f Is Nothing Then MsgBox f.Address
End Sub

thair younis
12-04-2011, 07:06 AM
Sub FindIT()
Dim f As Range
Set f = Columns("A:B").Find("Hamour")
If Not f Is Nothing Then MsgBox f.Address
End Sub

Hi
Thank you sir
I will try it and inform you
thanks again

thair younis
12-04-2011, 07:39 AM
sir Kenneth Hobs
I failed to put this code in right place
can you tell me where i should put this code
in my user form code exactly
thank you sir

Kenneth Hobs
12-04-2011, 08:40 AM
Again, without specific details, helping you is like going in circles. I can give you 10 solutions but then you would say that you need the 11th solution. The more that you detail your goal rather than how to get there, the more likely you are to get a viable solution.

You can call a Sub in a Module from any line of code in Userform code. The code need not be in a Module though.

e.g.

'In the Userform code:
Option Explicit

Private Sub CommandButton1_Click()
FindIT TextBox1.Value
Unload Me
End Sub

' In a Module:
Sub FindIT(fString As String)
Dim f As Range
Set f = Worksheets("Sheet1").Columns("A:B").Find(fString)
If Not f Is Nothing Then
MsgBox f.Address
f.Worksheet.Activate
f.Select
End If
End Sub

thair younis
12-07-2011, 02:05 AM
Hi
Mr Kenneth Hobs
I know i bother you perhaps but what i do i am not good in VBA
so i hope you help me and be patient with me
I want know where i put it in my code exactly please
Thank you so much




Private Sub CommandButton1_Click()
End

End Sub

Private Sub ListBox1_Click()

End Sub

Private Sub TextBox1_Change()
On Error Resume Next

Dim oil As Worksheet
Dim V As Integer, LastRow As Integer
Dim M As String
Dim Q, F
ListBox1.Clear
If TextBox1.Text = "" Then GoTo 1
M = TextBox1.Text
Set oil = Sheets("oil")
With oil
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row '


Set Q = .Range("A2:A" & LastRow).Find(M)




If Not Q Is Nothing Then
F = Q.Address
Do
If Application.WorksheetFunction.Search(M, Q, 1) = 1 Then



ListBox1.AddItem Q.Value


ListBox1.List(V, 1) = Q.Offset(0, 1).Value

ListBox1.List(V, 2) = Q.Offset(0, 2).Value

ListBox1.List(V, 3) = Q.Offset(0, 3).Value

ListBox1.List(V, 4) = Q.Offset(0, 4).Value

ListBox1.List(V, 5) = Q.Offset(0, 5).Value
ListBox1.List(V, 6) = Q.Offset(0, 6).Value
ListBox1.List(V, 7) = Q.Offset(0, 7).Value
ListBox1.List(V, 8) = Q.Offset(0, 8).Value
ListBox1.List(V, 9) = Q.Offset(0, 9).Value
ListBox1.List(V, 10) = Q.Offset(0, 10).Value



V = V + 1

End If
Set Q = .Range("A2:A" & LastRow).FindNext(Q)


Loop While Not Q Is Nothing And Q.Address <> F
End If
End With



1 End Sub

Private Sub UserForm_Click()

End Sub

End Sub

thair younis
12-08-2011, 12:23 AM
For up

mancubus
12-09-2011, 01:21 AM
The more that you detail your goal rather than how to get there, the more likely you are to get a viable solution.



:thumb:thumb:thumb

thair younis
12-09-2011, 10:56 AM
:thumb:thumb:thumb


Hi
If you wanna say something. say something help me .
Not quote from Mr Kenneth

mancubus
12-09-2011, 12:05 PM
just a reminder.
highligted, because i liked it.
no need to be so sensitive.


and you know... i will never, ever ask for someone's consent who to quote...

Kenneth Hobs
12-09-2011, 12:26 PM
I don't know what "for up" means. If you want a thread to bump to the top, just reply with the word bump. In your case, it is better to say why you need it bumped.

As my quoted string said, I don't really know what you want. You can put code anywhere you like. Whether that code accomplishes a goal or evens runs without error is another matter.

Try stating your goal in the most simple way that you can. If you can make up a simple example file with data and code that illustrates your problem, it is easier to help. This often overcomes language barriers.

When asking for help or clarification, there is no need to direct it to one person nor apologize. Others can often see what has been done and can give you feedback more quickly.