Redim Preserve?

silentwolf

Well-known Member
Joined
May 14, 2008
Messages
1,216
Office Version
  1. 2016
Hi guys,

I am struggling again gg../

Code:
Function MandatLoeschen(ByVal strText As String) As String
    Dim strSearch As String
    Dim varWoerter As Variant
    Dim lngCounter As Long

    
    Dim strMandat As String
    
    strSearch = "Mandatsnummer:"
    
    varWoerter = Split(strText, " ")
    
    For lngCounter = LBound(varWoerter) To UBound(varWoerter)
        If varWoerter(lngCounter) = strSearch Then
            MandatLoeschen = varWoerter(lngCounter) & " " & varWoerter(lngCounter + 1)
            
            
            MandatLoeschen = Replace(strText, MandatLoeschen, "")
            
        Else
     End If
    Next lngCounter
End Function

Following code works if I am not using it within my code..
When I run it from another code it delets the remaining records ..(
So I guess there need to be a redim preserve in it .. but in my case how does this one need to be??

Many thanks as always :)
 
HI shg,

Well it is a UDF Gg .) but I just did not think of an Exit For ...

Code:
Function MandatLoeschen(ByVal strText As String) As String
    Dim strSearch As String
    Dim varWoerter As Variant
    Dim lngCounter As Long

    Dim strMandat As String
    
    strSearch = "Mandatsnummer:"
    
    varWoerter = Split(strText, " ")
    
    For lngCounter = LBound(varWoerter) To UBound(varWoerter)
        If varWoerter(lngCounter) = strSearch Then
            MandatLoeschen = varWoerter(lngCounter) & " " & varWoerter(lngCounter + 1)
            MandatLoeschen = Replace(strText, MandatLoeschen, "")
    Exit For
    Else
        MandatLoeschen = strText
    End If

    Next lngCounter
End Function

Now it works as it supose to .) oh Mannnnnnnnnnnnnnyyyyyyyyy thanks gg :)

Tried so many different ways .. ggg oh dear time to go to bed I guess gg .
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
One question remains...

if you like to delete all of the remaining word after the word has been found..
Code:
MandatLoeschen = varWoerter(lngCounter) & " " & varWoerter(lngCounter + 1)
instead of this code above to have something
like
Code:
varWoerter(lbound(lngCounter) to varWoerter(ubound(varWoerter)
??

would be a quick way of getting rid of the remaining words if there are all been processed.
 
Last edited:
Upvote 0
It would help if you provided a clear example of input and desired results. I'm not going to guess.
 
Upvote 0
Hi thanks,
It would not be a set of exact data I need.. and in fact it does not matter what data it is... "Its about words and what words need to be kept and what not"

"Huber Pty.Ltd 12 Milller Street New York Mandatsnumber: 123456789 somemore Referenzpoints In the text"
"Huber Pty Ltd" should be the outcome but not always that is what I mean ,,, so if in this instants I like to start form the varWord(3)="12" till the last word in the text in this case text"
so get rid of all from"varWord(3) to varWord(uBound) in other cases it my start at varWord(10) and only to varWord(12)
So in my UDF I have a strSearch... string varible where I look for a word .. before it was the Mandatsnumber... so I look for a word in the text if it is found I like to either get rid of it or keep it or get rid of all other words..

By the way I am not sure how I can insert a excel sheet or anything like that here...

So it is not about any examples of what outcome or what data it is. All that matters is to be able to say from word(0) to word(3) should be kept and the rest goes.. or other situations ..
I look for a word which is the starting point so to say and then decide what I need and what not.

Hope it is a bit clearer?

Code:
    For lngCounter = LBound(varWoerter) To UBound(varWoerter)
        If varWoerter(lngCounter) = strSearch Then
'            strOut = varWoerter(lngCounter) & " " & varWoerter(lngCounter + 1)
            strOut = varWoerter(lngCounter + 1) & " " & varWoerter(UBound(varWoerter))
            BisZuGmbH = Replace(strText, strOut, "")
    Exit For

this is what I have tried so far...
 
Last edited:
Upvote 0
So if I got a text with companies with for example "Huber Industries Pty. Ltd 12 Miller Street New York Some More Referenzes noone really needs and they need to be out of the text but noone knows how many words are in the given Text"
This is not even the length of my string.. but if I need or like just "Huber Industries Pty. Ltd" and in another text it could be on a different location "Some stupid text in front of the Huber Industries Pty. Ltd then I need to find it just by searching"
For the Pty and then I like the return to be "Huber Industries Pty. Ltd" regardless where it would stand in the text.

Hope this is now better to understand?
 
Upvote 0
Here's what I mean by an example:

[Table="width:, class:grid"][tr][td="bgcolor:#C0C0C0"][/td][td="bgcolor:#C0C0C0"]
A​
[/td][td="bgcolor:#C0C0C0"]
B​
[/td][/tr][tr][td="bgcolor:#C0C0C0"]
1​
[/td][td="bgcolor:#F3F3F3"]
Input
[/td][td="bgcolor:#F3F3F3"]
Output
[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
2​
[/td][td]some input string[/td][td]output for that input[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
3​
[/td][td]another input string[/td][td]and for that one[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
4​
[/td][td]and a third[/td][td]and that one[/td][/tr]
[/table]


... supported by any explanation necessary to connect the dots.
 
Upvote 0
[TABLE="width: 796"]
<tbody>[TR]
[TD]I thought I wrote some examples before on the worksheet Huber IT Delivery Pty. Ltd[/TD]
[TD]Huber IT Delivery Pty. Ltd[/TD]
[/TR]
[TR]
[TD]Gerhard Müller GmbH REF: 5814252 1963524 Reference: Of some kind[/TD]
[TD]Gerhard Müller GmbH[/TD]
[/TR]
[TR]
[TD]This is 0004152 / ( 01 / 54 ) get this data out from somewhere/ Erika Summersoon, 19 Springfield[/TD]
[TD]Erika Summerspoon[/TD]
[/TR]
[TR]
[TD]X124 kjkjiu AU14575 Ref: Oh funny Data that is Make Night to day 15, 5487 What a Night 35 and what[/TD]
[TD]Make Night to day[/TD]
[/TR]
</tbody>[/TABLE]


[TABLE="width: 796"]
<tbody>[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
the tex would be much longer then this examples above so I am not sure if it would be a good idea to write those in here.
 
Last edited:
Upvote 0
Does the workbook contain a list of the phrases to be extracted?

How does this dovetail with the prior posts about looking for a specific word and the single word that follows?
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top