Solved

Excel VB To Copy Text In String and Paste In 2nd Worksheet

Posted on 2013-01-09
6
393 Views
Last Modified: 2013-01-09
Hello,

Can someone assist in developing a VB macro that will do the following:

1.  In Sheet1, column AG, there is a string of text and numbers.  The code looks at the string, and copys the text that appears between:  'Context ' & '@' symbol.  Please note there is a space that appears after 'Context' that should not be included in the copy.  The data being copied on average is 7 characters long.

2.  Paste that data in Sheet2, column A

Thank You!!!
0
Comment
Question by:Escanaba
  • 3
  • 3
6 Comments
 
LVL 1

Author Comment

by:Escanaba
ID: 38760428
One last note, the code should start in row 2 of column AG on Sheet1 and loop until there is no more data found in that column.  Thanks!
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 38760520
Question: does the string 'Context ' always appears, and is it always followed some number of characters later by an '@' symbol?
0
 
LVL 1

Author Comment

by:Escanaba
ID: 38760558
Yes.  The word Context_ will appear in every line that has text in it starting in row 2, and will always have characters following it with an @ symbol appearing after the characters.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 38760610
The following seems to work for me:

Sub DoIt()
    
    Dim LastR As Long
    
    With Worksheets("Sheet1")
        LastR = .Cells(.Rows.Count, "ag").End(xlUp).Row
    End With
    
    With Worksheets("Sheet2").Range("a2:a" & LastR)
        .EntireColumn.ClearContents
        .Formula = "=IF(Sheet1!AG2<>"""",MID(Sheet1!AG2," & _
            "SEARCH(""Context "",Sheet1!AG2)+8,SEARCH(""@"",Sheet1!AG2," & _
            "SEARCH(""Context "",Sheet1!AG2))-SEARCH(""Context "",Sheet1!AG2)-8),"""")"
        .Value = .Value
    End With
    
    MsgBox "Done"
    
End Sub

Open in new window

0
 
LVL 1

Author Closing Comment

by:Escanaba
ID: 38760691
Looks like that did the trick.  Thank you for putting this together!
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 38760712
You're welcome :)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now