Solved

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

Posted on 2013-01-09
6
396 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

803 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