Unterschied Function und Sub
16.01.2005 09:37:52
Reinhard
Moin Wissende,
ich weiss eine Function kann nurin der Zelle etwas reinschreiben, wo sie aufgerufen wird.
Aber warum kann sie nicht in anderen Zellen etwas suchen?
Das hat mich letztens sehr viel zeit gekostet, da ich nicht darauf kam warum nichts gefunden wird :-(
Nachstehend ist ein Beispiel Code für Sub und Function, die Sub läuft wie erwartet,
bei der Function bleibt c immer leer( =nothing) und der IF-Zweig wird nicht abgearbeitet.
Gruß aus dem schönwettrigen Meinhatten.
Reinhard
Sub testsub()
With Worksheets(1).Range("a1:a500")
Set c = .Find(2, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
MsgBox c.Address
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
End Sub
Function testfun()
With Worksheets(1).Range("a1:a500")
Set c = .Find(2, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
MsgBox c.Address
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
testfun = "huhu"
End Function