Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / October 2006

Tip: Looking for answers? Try searching our database.

Macro to extract in string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Calop - 14 Oct 2006 16:30 GMT
Any help with this is greatly appreciated.
Bob was graceous enough to provide the vba script below, however I now need
to make a minor change in it. It extracts part of a string in column A1 and
puts the results after the last row in col B. I have approx 200 rows that do
the same extraction. I would like to have the results placed in G1 thru
however many rows. Each extraction goes on same row as it's orginal. I know
to change the B to G for the column, but don't know what to change to have
the extracted part go to G1 and so on, down the rows.
Thank you, Calop
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
Bob Phillips - 14 Oct 2006 16:47 GMT
Calop,

Is it not just a case of changing both instances of

       Cells(iRow, "B").Value = CheckData(oCell)

to

       Cells(iRow, "G").Value = CheckData(oCell)

Signature

HTH

Bob Phillips

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

> Any help with this is greatly appreciated.
> Bob was graceous enough to provide the vba script below, however I now need
[quoted text clipped - 40 lines]
>
> End Function
Calop - 14 Oct 2006 19:49 GMT
Bob,
I made the change you mentioned and it did put the data in G as I need,
however when the data is extracted from A1, it puts the extracted data in G
column as last entry. I need it in G1. It takes the extracted data from A2
and places it in G1.
Thanks,
Calop
> Calop,
>
[quoted text clipped - 55 lines]
>>
>> End Function
Bob Phillips - 15 Oct 2006 20:08 GMT
Do you mean, extract A2 put in G1, A3 in G2, A4 in G5, etc. until column A
exhausted?

Signature

HTH

Bob Phillips

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

> Bob,
> I made the change you mentioned and it did put the data in G as I need,
[quoted text clipped - 62 lines]
> >>
> >> End Function
Calop - 15 Oct 2006 21:02 GMT
That is what it does now. I need to have it extract from A1 and put in G1,
A2 in G2,etc. until column is exhausted. Thanks for your patience.
Calop
> Do you mean, extract A2 put in G1, A3 in G2, A4 in G5, etc. until column A
> exhausted?
[quoted text clipped - 70 lines]
>> >>
>> >> End Function
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.