Kamis, 26 April 2012

[ExcelVBA] Finding several rows value according to data values

 

Hi friends. I having some difficulties in coding my vba. Hopefully all of you may guide me. Here are some of my data in excel.

A B

1. Amirul 12345

2. Norlela 12121

3. Amirul 23456

4. Amirul 45678

I do have several checkbox and i want to find row's value according to data which I put in certain CheckBox field. Each time I run, I would like to have different value if the data is the same value. Eg: If I put value on CheckBox is "Amirul", I would like the coding give me answer "1". When I run again, vba give me answer "3". Then next time i run answer would be "4". Unless there is no longer same value in the database.Can anyone help me to code the coding? I'll put in capital letter where i wanna code to be placed.

Here my initial coding :

Private Sub CommandButton9_Click()
Dim ws As Worksheet
Dim xfilter As String
Dim xFind, xRow As Range
Set ws = Worksheets("Rekod")

'to confirm only 1 checkbox are clicked
If CheckBox1.Value = True And _
CheckBox2.Value And _
CheckBox3.Value = True Then
MsgBox "Sila Klik Satu Pilihan Sahaja"

ElseIf CheckBox1.Value = True And _
CheckBox2.Value = True Then
MsgBox "Sila Klik Satu Pilihan Sahaja"

ElseIf CheckBox1.Value = True And _
CheckBox3.Value = True Then
MsgBox "Sila Klik Satu Pilihan Sahaja"

ElseIf CheckBox2.Value = True And _
CheckBox3.Value = True Then
MsgBox "Sila Klik Satu Pilihan Sahaja"

End If

' to determine filter
If CheckBox1.Value = True Then
xfilter = spk.Value
End If

If CheckBox2.Value = True Then
xfilter = penerima.Value
End If

If CheckBox3.Value = True Then
xfilter = utmfin.Value
End If

'to find exact data
>>>> HERE I WANT TO PUT THE CODING. MY CODING WAS TOTALLY WRONG..>>>
xRow = xRow + 1
Set xFind = ws.Range("Database" - xRow).Find(what:=xfilter, MatchCase:=True)

If xFind Is Nothing Then
MsgBox "Tiada Rekod Dijumpai"

Else
MsgBox xFind.Row
'to show relevant data

End If

End Sub

__._,_.___
Recent Activity:
----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.

----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA

----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com

----------------------------------
.

__,_._,___

Tidak ada komentar:

Posting Komentar