+ Reply to Thread
Results 1 to 7 of 7

Macro to search rows for specific text within a cell then cut cell to specified location

  1. #1
    Registered User
    Join Date
    08-24-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    6

    Macro to search rows for specific text within a cell then cut cell to specified location

    Hi,

    I'm new to all this macro creating and was wondering if someone could help me. I have a load of un organised addresses in rows (approx 6000):

    House, Address 1, Address 2, Postcode, Tel, Fax, Email
    House, Address 1, Address 2, Address 3, Postcode, Tel, Fax, Email
    House, Address 1, Address 2, Address 3, Address 4, Postcode, Tel, Fax, Email
    House, Address 1, Address 2, Postcode, Tel, Fax, Email

    All the addresses are different lengths so I need a macro (or formula if more applicable) to extract the cell with the email address in and then write it to a cell further over to the right. Luckily the Email, Tel and Fax all state 'Email', 'Tel' or 'Fax' in the cell, so this might be able to be used to sort.

    So what I'm looking to end up with is:

    House, Address 1, Address 2, Postcode, Tel, Fax, Email
    House, Address 1, Address 2, Address 3, Postcode, Tel, Fax, Email
    House, Address 1, Address 2, Address 3, Address 4, Postcode, Tel, Fax, Email
    House, Address 1, Address 2, Postcode, Tel, Fax, Email

    Help is much appreciated, thank you in advance.

    Jonathan

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Macro to search rows for specific text within a cell then cut cell to specified locati

    can you attach a sample file (not 6000 rows, but 20) with before an after situation ?
    If solved remember to mark Thread as solved

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro to search rows for specific text within a cell then cut cell to specified locati

    Hi, Jonathan ,

    if all contents resides within one cell you could apply TextToColumns to split the contents up.

    If you want to work with formulae you could utilize Find and search for the keyword (Find will deliver the position of the first character in that cell) and use the Mid-Function to filter the rest of the cell.

    BTW: I use Firefox14, and I canīt make up a difference in both sections showing the data.

    Ciao,
    Holger

  4. #4
    Registered User
    Join Date
    08-24-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro to search rows for specific text within a cell then cut cell to specified locati

    Hi Holger

    The data is each in individual cells.

    What I want is to pull out the "email" cell and move it to the right, but the cell with the address is not consistently the same column.

    Thanks

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro to search rows for specific text within a cell then cut cell to specified locati

    Hi, Jonathan,

    if the Email is either hyperlink or text including @ we can narrow down the range to look in to the columns G to J and run a macro on this range (will only copy the contents, if you need hyperlinks please come back):

    Please Login or Register  to view this content.
    Ciao,
    Holger
    Last edited by HaHoBe; 08-25-2012 at 04:00 AM. Reason: columns ion text should be equal to columns in code used

  6. #6
    Registered User
    Join Date
    08-24-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro to search rows for specific text within a cell then cut cell to specified locati

    Hi Holger, that macro is great, how do I tweak it to search for cells not including certain text? Thanks a lot

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro to search rows for specific text within a cell then cut cell to specified locati

    Hi, jonathanpotts90,

    InStr delivers the position of the first character of the searched string inside to string and will deliver 0 if no match is found. So if no match is needed just change the greater sign to equal (from the code)
    Please Login or Register  to view this content.
    Please be aware that in the example the same column is used as I expected only one email to be inside each row. If more than one instance is found, either add to the cell like
    Please Login or Register  to view this content.
    Or use a counter if still in the same row to utilize Offset from the destination column.

    Ciao,
    Holger

  8. #8
    Registered User
    Join Date
    08-24-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro to search rows for specific text within a cell then cut cell to specified locati

    Ok that's great, last tweak, how can I get anything but the email and contact

    think its this line that needs a list

    If InStr(1, rngCell, "Email" "Contact") = 0 Then

  9. #9
    Registered User
    Join Date
    08-24-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro to search rows for specific text within a cell then cut cell to specified locati

    Ok that's great, last tweak, how can I get anything but the email and contact

    think its this line that needs a list

    If InStr(1, rngCell, "Email" "Contact") = 0 Then

    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1