PC Review


Reply
Thread Tools Rate Thread

macro that strips data from string

 
 
Calop
Guest
Posts: n/a
 
      17th Sep 2006
Hi,
I am new to VBA & Macros. Appreciate any help I can get. I have a macro that
strip's data from a string and it works fine except I need it to strip
further in the string. example of results:
bunder_linn-S1/0-720L-140.55.135.34-NIPR-1.5M(In)

What I need is to strip from the second - to the (
example: bunder_linn-S1/0-720L-140.55.135.34-NIPR-1.5M(In)


It can strip and copy to clipboard or to cell b1. Either way will work. This
macro was in a word doc, will it work in excel also?

Sub AREA_REPORT()
'
' AREA_REPORT Macro
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "[-]*[(]"
.Replacement.Text = " ("
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.WholeStory
Selection.Cut
End Sub

Thanks,
Calop


 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      17th Sep 2006
Sub AREA_REPORT()
Dim oCell As Range
Dim iPos1 As Long
Dim iPos2 As Long

Set oCell = Selection.Find("*-*(*")
If Not oCell Is Nothing Then
iPos1 = InStr(oCell.Value, "-")
If iPos1 > 0 Then
iPos1 = InStr(iPos1 + 1, oCell.Value, "-")
If iPos1 > 0 Then
iPos2 = InStr(iPos2 + 1, oCell.Value, "(")
Range("B1").Value = Left(oCell.Value, iPos1 - 1) & _
Right(oCell.Value, Len(oCell.Value) - iPos2)
End If
End If
End If

End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Calop" <(E-Mail Removed)> wrote in message
news:JufPg.40$(E-Mail Removed)...
> Hi,
> I am new to VBA & Macros. Appreciate any help I can get. I have a macro

that
> strip's data from a string and it works fine except I need it to strip
> further in the string. example of results:
> bunder_linn-S1/0-720L-140.55.135.34-NIPR-1.5M(In)
>
> What I need is to strip from the second - to the (
> example: bunder_linn-S1/0-720L-140.55.135.34-NIPR-1.5M(In)
>
>
> It can strip and copy to clipboard or to cell b1. Either way will work.

This
> macro was in a word doc, will it work in excel also?
>
> Sub AREA_REPORT()
> '
> ' AREA_REPORT Macro
> '
> Selection.Find.ClearFormatting
> Selection.Find.Replacement.ClearFormatting
> With Selection.Find
> .Text = "[-]*[(]"
> .Replacement.Text = " ("
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchCase = False
> .MatchWholeWord = False
> .MatchAllWordForms = False
> .MatchSoundsLike = False
> .MatchWildcards = True
> End With
> Selection.Find.Execute Replace:=wdReplaceAll
> Selection.WholeStory
> Selection.Cut
> End Sub
>
> Thanks,
> Calop
>
>



 
Reply With Quote
 
 
 
 
Calop
Guest
Posts: n/a
 
      17th Sep 2006
Bob, Thank you for the quick response. The macro works good but at the end
of the string I need the (In) to look like this. Also if there are 50 to 100
rows in column A, what do I put to strip all at once. Again, thank you.
Calop
"Bob Phillips" <(E-Mail Removed)> wrote in message
news:%23g$(E-Mail Removed)...
> Sub AREA_REPORT()
> Dim oCell As Range
> Dim iPos1 As Long
> Dim iPos2 As Long
>
> Set oCell = Selection.Find("*-*(*")
> If Not oCell Is Nothing Then
> iPos1 = InStr(oCell.Value, "-")
> If iPos1 > 0 Then
> iPos1 = InStr(iPos1 + 1, oCell.Value, "-")
> If iPos1 > 0 Then
> iPos2 = InStr(iPos2 + 1, oCell.Value, "(")
> Range("B1").Value = Left(oCell.Value, iPos1 - 1) & _
> Right(oCell.Value, Len(oCell.Value) - iPos2)
> End If
> End If
> End If
>
> End Sub
>
>
> --
> HTH
>
> Bob Phillips
>
> (replace somewhere in email address with gmail if mailing direct)
>
> "Calop" <(E-Mail Removed)> wrote in message
> news:JufPg.40$(E-Mail Removed)...
>> Hi,
>> I am new to VBA & Macros. Appreciate any help I can get. I have a macro

> that
>> strip's data from a string and it works fine except I need it to strip
>> further in the string. example of results:
>> bunder_linn-S1/0-720L-140.55.135.34-NIPR-1.5M(In)
>>
>> What I need is to strip from the second - to the (
>> example: bunder_linn-S1/0-720L-140.55.135.34-NIPR-1.5M(In)
>>
>>
>> It can strip and copy to clipboard or to cell b1. Either way will work.

> This
>> macro was in a word doc, will it work in excel also?
>>
>> Sub AREA_REPORT()
>> '
>> ' AREA_REPORT Macro
>> '
>> Selection.Find.ClearFormatting
>> Selection.Find.Replacement.ClearFormatting
>> With Selection.Find
>> .Text = "[-]*[(]"
>> .Replacement.Text = " ("
>> .Forward = True
>> .Wrap = wdFindContinue
>> .Format = False
>> .MatchCase = False
>> .MatchWholeWord = False
>> .MatchAllWordForms = False
>> .MatchSoundsLike = False
>> .MatchWildcards = True
>> End With
>> Selection.Find.Execute Replace:=wdReplaceAll
>> Selection.WholeStory
>> Selection.Cut
>> End Sub
>>
>> Thanks,
>> Calop
>>
>>

>
>



 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      17th Sep 2006
Sub AREA_REPORT()
Dim oCell As Range
Dim tmp As String
Dim iRow As Long
Dim sFirst As String

Set oCell = Selection.Find("*-*(*")
If Not oCell Is Nothing Then
iRow = iRow + 1
Cells(iRow, "B").Value = CheckData(oCell)
sFirst = oCell.Address
Do
Set oCell = Selection.FindNext(oCell)
If Not oCell Is Nothing Then
If oCell.Address <> sFirst Then
iRow = iRow + 1
Cells(iRow, "B").Value = CheckData(oCell)
End If
End If
Loop While Not oCell Is Nothing And oCell.Address <> sFirst
End If

End Sub

Private Function CheckData(cell As Range)
Dim iPos1 As Long
Dim iPos2 As Long

iPos1 = InStr(cell.Value, "-")
iPos1 = InStr(iPos1 + 1, cell.Value, "-")
iPos2 = InStr(iPos2 + 1, cell.Value, "(")
CheckData = Left(cell.Value, iPos1 - 1) & _
Right(cell.Value, Len(cell.Value) - iPos2 + 1)

End Function


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Calop" <(E-Mail Removed)> wrote in message
news:zGhPg.26$(E-Mail Removed)...
> Bob, Thank you for the quick response. The macro works good but at the

end
> of the string I need the (In) to look like this. Also if there are 50 to

100
> rows in column A, what do I put to strip all at once. Again, thank you.
> Calop
> "Bob Phillips" <(E-Mail Removed)> wrote in message
> news:%23g$(E-Mail Removed)...
> > Sub AREA_REPORT()
> > Dim oCell As Range
> > Dim iPos1 As Long
> > Dim iPos2 As Long
> >
> > Set oCell = Selection.Find("*-*(*")
> > If Not oCell Is Nothing Then
> > iPos1 = InStr(oCell.Value, "-")
> > If iPos1 > 0 Then
> > iPos1 = InStr(iPos1 + 1, oCell.Value, "-")
> > If iPos1 > 0 Then
> > iPos2 = InStr(iPos2 + 1, oCell.Value, "(")
> > Range("B1").Value = Left(oCell.Value, iPos1 - 1) & _
> > Right(oCell.Value, Len(oCell.Value) - iPos2)
> > End If
> > End If
> > End If
> >
> > End Sub
> >
> >
> > --
> > HTH
> >
> > Bob Phillips
> >
> > (replace somewhere in email address with gmail if mailing direct)
> >
> > "Calop" <(E-Mail Removed)> wrote in message
> > news:JufPg.40$(E-Mail Removed)...
> >> Hi,
> >> I am new to VBA & Macros. Appreciate any help I can get. I have a macro

> > that
> >> strip's data from a string and it works fine except I need it to strip
> >> further in the string. example of results:
> >> bunder_linn-S1/0-720L-140.55.135.34-NIPR-1.5M(In)
> >>
> >> What I need is to strip from the second - to the (
> >> example: bunder_linn-S1/0-720L-140.55.135.34-NIPR-1.5M(In)
> >>
> >>
> >> It can strip and copy to clipboard or to cell b1. Either way will work.

> > This
> >> macro was in a word doc, will it work in excel also?
> >>
> >> Sub AREA_REPORT()
> >> '
> >> ' AREA_REPORT Macro
> >> '
> >> Selection.Find.ClearFormatting
> >> Selection.Find.Replacement.ClearFormatting
> >> With Selection.Find
> >> .Text = "[-]*[(]"
> >> .Replacement.Text = " ("
> >> .Forward = True
> >> .Wrap = wdFindContinue
> >> .Format = False
> >> .MatchCase = False
> >> .MatchWholeWord = False
> >> .MatchAllWordForms = False
> >> .MatchSoundsLike = False
> >> .MatchWildcards = True
> >> End With
> >> Selection.Find.Execute Replace:=wdReplaceAll
> >> Selection.WholeStory
> >> Selection.Cut
> >> End Sub
> >>
> >> Thanks,
> >> Calop
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
Calop
Guest
Posts: n/a
 
      17th Sep 2006
Thank you for your expertise. It works like a charm. This was my first
experience with a newsgroup, and I am totally impressed.
Calop
"Bob Phillips" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Sub AREA_REPORT()
> Dim oCell As Range
> Dim tmp As String
> Dim iRow As Long
> Dim sFirst As String
>
> Set oCell = Selection.Find("*-*(*")
> If Not oCell Is Nothing Then
> iRow = iRow + 1
> Cells(iRow, "B").Value = CheckData(oCell)
> sFirst = oCell.Address
> Do
> Set oCell = Selection.FindNext(oCell)
> If Not oCell Is Nothing Then
> If oCell.Address <> sFirst Then
> iRow = iRow + 1
> Cells(iRow, "B").Value = CheckData(oCell)
> End If
> End If
> Loop While Not oCell Is Nothing And oCell.Address <> sFirst
> End If
>
> End Sub
>
> Private Function CheckData(cell As Range)
> Dim iPos1 As Long
> Dim iPos2 As Long
>
> iPos1 = InStr(cell.Value, "-")
> iPos1 = InStr(iPos1 + 1, cell.Value, "-")
> iPos2 = InStr(iPos2 + 1, cell.Value, "(")
> CheckData = Left(cell.Value, iPos1 - 1) & _
> Right(cell.Value, Len(cell.Value) - iPos2 + 1)
>
> End Function
>
>
> --
> HTH
>
> Bob Phillips
>
> (replace somewhere in email address with gmail if mailing direct)
>
> "Calop" <(E-Mail Removed)> wrote in message
> news:zGhPg.26$(E-Mail Removed)...
>> Bob, Thank you for the quick response. The macro works good but at the

> end
>> of the string I need the (In) to look like this. Also if there are 50 to

> 100
>> rows in column A, what do I put to strip all at once. Again, thank you.
>> Calop
>> "Bob Phillips" <(E-Mail Removed)> wrote in message
>> news:%23g$(E-Mail Removed)...
>> > Sub AREA_REPORT()
>> > Dim oCell As Range
>> > Dim iPos1 As Long
>> > Dim iPos2 As Long
>> >
>> > Set oCell = Selection.Find("*-*(*")
>> > If Not oCell Is Nothing Then
>> > iPos1 = InStr(oCell.Value, "-")
>> > If iPos1 > 0 Then
>> > iPos1 = InStr(iPos1 + 1, oCell.Value, "-")
>> > If iPos1 > 0 Then
>> > iPos2 = InStr(iPos2 + 1, oCell.Value, "(")
>> > Range("B1").Value = Left(oCell.Value, iPos1 - 1) & _
>> > Right(oCell.Value, Len(oCell.Value) - iPos2)
>> > End If
>> > End If
>> > End If
>> >
>> > End Sub
>> >
>> >
>> > --
>> > HTH
>> >
>> > Bob Phillips
>> >
>> > (replace somewhere in email address with gmail if mailing direct)
>> >
>> > "Calop" <(E-Mail Removed)> wrote in message
>> > news:JufPg.40$(E-Mail Removed)...
>> >> Hi,
>> >> I am new to VBA & Macros. Appreciate any help I can get. I have a
>> >> macro
>> > that
>> >> strip's data from a string and it works fine except I need it to strip
>> >> further in the string. example of results:
>> >> bunder_linn-S1/0-720L-140.55.135.34-NIPR-1.5M(In)
>> >>
>> >> What I need is to strip from the second - to the (
>> >> example: bunder_linn-S1/0-720L-140.55.135.34-NIPR-1.5M(In)
>> >>
>> >>
>> >> It can strip and copy to clipboard or to cell b1. Either way will
>> >> work.
>> > This
>> >> macro was in a word doc, will it work in excel also?
>> >>
>> >> Sub AREA_REPORT()
>> >> '
>> >> ' AREA_REPORT Macro
>> >> '
>> >> Selection.Find.ClearFormatting
>> >> Selection.Find.Replacement.ClearFormatting
>> >> With Selection.Find
>> >> .Text = "[-]*[(]"
>> >> .Replacement.Text = " ("
>> >> .Forward = True
>> >> .Wrap = wdFindContinue
>> >> .Format = False
>> >> .MatchCase = False
>> >> .MatchWholeWord = False
>> >> .MatchAllWordForms = False
>> >> .MatchSoundsLike = False
>> >> .MatchWildcards = True
>> >> End With
>> >> Selection.Find.Execute Replace:=wdReplaceAll
>> >> Selection.WholeStory
>> >> Selection.Cut
>> >> End Sub
>> >>
>> >> Thanks,
>> >> Calop
>> >>
>> >>
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      18th Sep 2006
Great. Hope to see you again.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Calop" <(E-Mail Removed)> wrote in message
news:iBiPg.38$(E-Mail Removed)...
> Thank you for your expertise. It works like a charm. This was my first
> experience with a newsgroup, and I am totally impressed.
> Calop
> "Bob Phillips" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Sub AREA_REPORT()
> > Dim oCell As Range
> > Dim tmp As String
> > Dim iRow As Long
> > Dim sFirst As String
> >
> > Set oCell = Selection.Find("*-*(*")
> > If Not oCell Is Nothing Then
> > iRow = iRow + 1
> > Cells(iRow, "B").Value = CheckData(oCell)
> > sFirst = oCell.Address
> > Do
> > Set oCell = Selection.FindNext(oCell)
> > If Not oCell Is Nothing Then
> > If oCell.Address <> sFirst Then
> > iRow = iRow + 1
> > Cells(iRow, "B").Value = CheckData(oCell)
> > End If
> > End If
> > Loop While Not oCell Is Nothing And oCell.Address <> sFirst
> > End If
> >
> > End Sub
> >
> > Private Function CheckData(cell As Range)
> > Dim iPos1 As Long
> > Dim iPos2 As Long
> >
> > iPos1 = InStr(cell.Value, "-")
> > iPos1 = InStr(iPos1 + 1, cell.Value, "-")
> > iPos2 = InStr(iPos2 + 1, cell.Value, "(")
> > CheckData = Left(cell.Value, iPos1 - 1) & _
> > Right(cell.Value, Len(cell.Value) - iPos2 + 1)
> >
> > End Function
> >
> >
> > --
> > HTH
> >
> > Bob Phillips
> >
> > (replace somewhere in email address with gmail if mailing direct)
> >
> > "Calop" <(E-Mail Removed)> wrote in message
> > news:zGhPg.26$(E-Mail Removed)...
> >> Bob, Thank you for the quick response. The macro works good but at the

> > end
> >> of the string I need the (In) to look like this. Also if there are 50

to
> > 100
> >> rows in column A, what do I put to strip all at once. Again, thank you.
> >> Calop
> >> "Bob Phillips" <(E-Mail Removed)> wrote in message
> >> news:%23g$(E-Mail Removed)...
> >> > Sub AREA_REPORT()
> >> > Dim oCell As Range
> >> > Dim iPos1 As Long
> >> > Dim iPos2 As Long
> >> >
> >> > Set oCell = Selection.Find("*-*(*")
> >> > If Not oCell Is Nothing Then
> >> > iPos1 = InStr(oCell.Value, "-")
> >> > If iPos1 > 0 Then
> >> > iPos1 = InStr(iPos1 + 1, oCell.Value, "-")
> >> > If iPos1 > 0 Then
> >> > iPos2 = InStr(iPos2 + 1, oCell.Value, "(")
> >> > Range("B1").Value = Left(oCell.Value, iPos1 - 1) & _
> >> > Right(oCell.Value, Len(oCell.Value) - iPos2)
> >> > End If
> >> > End If
> >> > End If
> >> >
> >> > End Sub
> >> >
> >> >
> >> > --
> >> > HTH
> >> >
> >> > Bob Phillips
> >> >
> >> > (replace somewhere in email address with gmail if mailing direct)
> >> >
> >> > "Calop" <(E-Mail Removed)> wrote in message
> >> > news:JufPg.40$(E-Mail Removed)...
> >> >> Hi,
> >> >> I am new to VBA & Macros. Appreciate any help I can get. I have a
> >> >> macro
> >> > that
> >> >> strip's data from a string and it works fine except I need it to

strip
> >> >> further in the string. example of results:
> >> >> bunder_linn-S1/0-720L-140.55.135.34-NIPR-1.5M(In)
> >> >>
> >> >> What I need is to strip from the second - to the (
> >> >> example: bunder_linn-S1/0-720L-140.55.135.34-NIPR-1.5M(In)
> >> >>
> >> >>
> >> >> It can strip and copy to clipboard or to cell b1. Either way will
> >> >> work.
> >> > This
> >> >> macro was in a word doc, will it work in excel also?
> >> >>
> >> >> Sub AREA_REPORT()
> >> >> '
> >> >> ' AREA_REPORT Macro
> >> >> '
> >> >> Selection.Find.ClearFormatting
> >> >> Selection.Find.Replacement.ClearFormatting
> >> >> With Selection.Find
> >> >> .Text = "[-]*[(]"
> >> >> .Replacement.Text = " ("
> >> >> .Forward = True
> >> >> .Wrap = wdFindContinue
> >> >> .Format = False
> >> >> .MatchCase = False
> >> >> .MatchWholeWord = False
> >> >> .MatchAllWordForms = False
> >> >> .MatchSoundsLike = False
> >> >> .MatchWildcards = True
> >> >> End With
> >> >> Selection.Find.Execute Replace:=wdReplaceAll
> >> >> Selection.WholeStory
> >> >> Selection.Cut
> >> >> End Sub
> >> >>
> >> >> Thanks,
> >> >> Calop
> >> >>
> >> >>
> >> >
> >> >
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XP SP2 strips some attachments from Outlook Express Peter Landau Windows XP Security 0 16th Nov 2004 02:56 PM
Windows XP strips "harmful" attachments Al Franco Windows XP General 4 31st Mar 2004 03:41 PM
Outlook Express 6.0 strips incoming attachments riles Windows XP Internet Explorer 2 31st Dec 2003 08:50 PM
Outlook w/Exchange Strips message text but leaves attachments Bryan Greene Microsoft Outlook 0 29th Oct 2003 01:14 PM
Outlook strips my Singnature Graphic! Ron Boetger Microsoft Outlook 0 24th Oct 2003 01:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:00 PM.