• Privacywetgeving
    Het is bij Helpmij.nl niet toegestaan om persoonsgegevens in een voorbeeld te plaatsen. Alle voorbeelden die persoonsgegevens bevatten zullen zonder opgaaf van reden verwijderd worden. In de vraag zal specifiek vermeld moeten worden dat het om fictieve namen gaat.

gebruiken Find in vba

Status
Niet open voor verdere reacties.

geep1980

Gebruiker
Lid geworden
7 apr 2009
Berichten
348
Ik heb een kolom waarin allemaal gegevens worden geimporteerd waar een % in voor komt gevolgd door text.
Nu wil ik een macro die in het volgende doet
=LEFT(B2,find("%",B2,1)-1)


Nu heb ik zelf dit geprobeerd maar heleaas zonder resultaat:
Dim a As Range
For Each a In Worksheets("Sheet2").Range("B3:B10")
If a.Value > " " Then a.Value = Left(a.Value, Find("%", a.Value, 1))
Next
ik krijg de melding compile error
sub of function not defined en dat geeft hij op de find

Helaas is niet altijd de lengte gelijk. Het kan dus zijn dat er 50.00% (50.00%), 1.0% (1.0%) staat

Hoe kan ik dit het beste doen?
 
exhelp bedankt voor het verwijzen naar de pagina.
Ik heb het voor elkaar.
Zal best wel op een mooiere manier geschreven kunnen worden maar dit werkt:

Dim R As Range, FindAddress As String


'Search for all the occurrences of the item.
With Worksheets("Sheet2").Range("B:B")
Set R = .Find("*%*", Lookat:=xlWhole)
'If a match is found.
If Not R Is Nothing Then
'Store the address of the cell where the first match is found in a variable.
FindAddress = R.Address
'Start to loop.
Do
' Do a left of all cell
R = Left(R, 6)
'Search the next cell with a matching value.
Set R = .FindNext(R)
'Loop as long matches are found, and the address of the cell where a match is found,
'is <> as the address of the cell where the first match is found (FindAddress).
Loop While Not R Is Nothing And R.Address <> FindAddress
End If
End With

'Clear memory.
Set R = Nothing
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan