Søgefunktion i userform
Tillæg til spørgsmål http://www.eksperten.dk/spm/768117Supertekst har udarbejdet nedenstående sub til brug for en søgefunktion i Excel. Søgefunktionen har bare den svaghed, at den kun søger efter det eksakte ord og ikke bare en del af ordet.
Hvis jeg søger efter abc vil jeg gerne finde alle de celler som indeholder abc, det vil sige også celler indeholdende abcd, 2abc m.v.
Er der en der kan hjælpe mig med en tilpasning af funktionen?
Program i Modul:
Dim Ru As Variant, tabel(), ix, antalFundne
Private Sub SpinButton1_spinUp()
If ix - 1 >= 1 Then
ix = ix - 1
visIndex
End If
End Sub
Private Sub SpinButton1_spinDown()
If ix + 1 <= antalFundne Then
ix = ix + 1
visIndex
End If
End Sub
Private Sub UserForm_activate()
Ru = ActiveWorkbook.Sheets(1).Ra
antalFundne = tælantalFundne
ReDim tabel(antalFundne)
sætItabel
ix = 1
visIndex
End Sub
Private Sub visIndex()
Me.L_index.Caption = CStr(ix) + "/" + CStr(antalFundne)
Me.L_celle.Caption = tabel(ix)
Rem vis aktuelle celle
Range(tabel(ix)).Select
End Sub
Private Function tælantalFundne()
If Len(Ru) > 0 Then
tælantalFundne = 1
For f = 1 To Len(Ru)
If Mid(Ru, f, 1) = "," Then
tælantalFundne = tælantalFundne + 1
End If
Next f
End If
End Function
Private Sub sætItabel()
Dim p, Wu, part, ix
Wu = Ru
ix = 1
If Len(Wu) > 0 Then
While InStr(Wu, ",") > 0
p = InStr(Wu, ",")
If p > 0 Then
tabel(ix) = Left(Wu, p - 1)
ix = ix + 1
Wu = Mid(Wu, p + 1)
End If
Wend
End If
Rem sidste element
If Wu <> "" Then
tabel(ix) = Wu
End If
End Sub
Program i Ark1:
Public Ra As Variant
Sub Søg()
Ra = ""
Rem Indput til søgning
frmS.Show
Rem Opsamling af celler, der opfylder kriterie (test)
For r = 1 To ActiveCell.SpecialCells(xlLastCell).Row
If Cells(r, 1) = Range("SogOrd").Value Then
Ra = Ra + "A" & CStr(r) & ","
End If
Next r
Rem Opret range
Ra = Left(Ra, Len(Ra) - 1)
Load UserForm1
UserForm1.Show 0
End Sub
