06. april 2010 - 13:18Der er
2 kommentarer og 1 løsning
Brug af Excels "MATCH" funktion i VBA
Jeg har en Excel funktion, der gerne skal bygges ind i mit VBA-script.
Som det er nu, har jeg to ark: Ark1 og Ark2
I Ark1 har jeg en celle (H2), som har en værdi (Dato). Den værdi skal findes i en kolonne i Ark2, og rækkenummeren skal returneres.
Funktionen i Excel er: =RÆKKE(INDIREKTE(ADRESSE(SAMMENLIGN(H2;Ark2!$A:$A;0);1;4)))
Jeg har forsøgt mig med Application.Match, men får fejl.
Sub testMatch() Dim myvalue As Long Dim matchtext As String Sheets("Ark1").Select matchtext = ActiveSheet.Range("H2").Text Sheets("Ark2").Select myvalue = Application.Match(matchtext, Range("A6:A10000"), 0) MsgBox (myvalue) End Sub
Sub testMatch() Dim myvalue As Long Dim matchtext As String Sheets("Ark1").Select matchtext = ActiveSheet.Range("H2").Text Sheets("Ark2").Select myvalue = findDato("A6:A10000", matchtext) MsgBox (myvalue) End Sub Public Function findDato(område, id) With ActiveSheet.Range(område) Set c = .Find(id, LookIn:=xlValues, LookAt:=xlWhole) If Not c Is Nothing Then findDato = c.Row Else findDato = 0 End If End With End Function
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.