Avatar billede alen32 Nybegynder
22. marts 2005 - 22:33 Der er 2 kommentarer og
1 løsning

Makro hjælp?

Hej!
Jeg har fundet denne makro som søger efter 3 ord i samme række og hvis de findes skrives der i listbox. I starten har jeg 2 optionknapper hvor man kan vælge hest eller gris. Jeg vil gerne tilføje 3 optionknap som finder både hest og gris.

her er makro:
Private Sub CommandButton1_Click()
With UserForm1
    If .OptionButton1 Then
        sOne = "Horse"
    Else
        sOne = "Pig"
    End If
    If .OptionButton3 Then
          sTwo = "Danish"
    Else
          sTwo = "Foreign"
    End If
    sThree = .TextBox1.Text
End With
With Worksheets(1).Cells
    Set c = .Find(sOne, LookIn:=xlValues)
    If Not c Is Nothing Then
        firstAddress = c.Address
        Do
          If Application.CountIf(c.EntireRow, "*" & sTwo & "*") And _
            Application.CountIf(c.EntireRow, "*" & sThree & "*") Then
                  UserForm1.ListBox1.AddItem c.Value
                  UserForm1.ListBox1.List( _
                      UserForm1.ListBox1.ListCount - 1, 1) _
                          = c.Offset(0, 2).Value
                    UserForm1.ListBox1.List( _
                        UserForm1.ListBox1.ListCount - 1, 2) _
                          = c.Offset(0, 5).Value
          End If
            Set c = .FindNext(c)
        Loop While Not c Is Nothing And c.Address <> firstAddress
    End If
End With
End Sub
Avatar billede bak Forsker
23. marts 2005 - 18:00 #1
Private Sub CommandButton1_Click()
  Dim sOne, sOneItem
  With UserForm1
      '******
      If .OptionButton1 Then sOne = Array("Horse")
      If .OptionButton2 Then sOne = Array("Pig")
      If .OptionButton5 Then sOne = Array("Horse", "Pig")
      '******
      If .OptionButton3 Then
        sTwo = "Danish"
      Else
        sTwo = "Foreign"
      End If
      sThree = .TextBox1.Text
  End With
 
  '******
  For Each sOneItem In sOne
  '******
  'MsgBox sOneItem
      With Worksheets(1).Cells
        Set c = .Find(sOneItem, LookIn:=xlValues)
        If Not c Is Nothing Then
            firstAddress = c.Address
            Do
              If Application.CountIf(c.EntireRow, "*" & sTwo & "*") And _
                  Application.CountIf(c.EntireRow, "*" & sThree & "*") Then
                  UserForm1.ListBox1.AddItem c.Value
                  UserForm1.ListBox1.List( _
                        UserForm1.ListBox1.ListCount - 1, 1) _
                        = c.Offset(0, 2).Value
                  UserForm1.ListBox1.List( _
                        UserForm1.ListBox1.ListCount - 1, 2) _
                        = c.Offset(0, 5).Value
              End If
              Set c = .FindNext(c)
            Loop While Not c Is Nothing And c.Address <> firstAddress
        End If
      End With
  '******
  Next
  '******
End Sub
Avatar billede alen32 Nybegynder
23. marts 2005 - 21:50 #2
tak det virker
send et svar
Avatar billede bak Forsker
23. marts 2005 - 22:07 #3
s'føli :-)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Excel kurser for alle niveauer og behov – find det kursus, der passer til dig

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester