Solved

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

Posted on 2013-01-09
6
394 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

22 Experts available now in Live!

Get 1:1 Help Now