+ Reply to Thread
Results 1 to 13 of 13

Selecting cell that contains text and merging without data loss.

  1. #1
    Registered User
    Join Date
    05-14-2015
    Location
    IOWA CITY, IOWA, USA
    MS-Off Ver
    2010
    Posts
    30

    Selecting cell that contains text and merging without data loss.

    I am trying to come up with a code that will search through a column (H).
    This column contains mostly numbers, but due to the method in which i must import this data some times it gets screwy and puts in a line of text.

    So when searching through Column H I want to find cells that contain text instead of numbers and merge these to the cell to the left (same row, column G) without losing the data, and then delete the cell in column H and shift the rest of the row left.

    This will help me get all of my cells lined up properly.


    So I have the code for merging the cells, I am mostly having trouble with getting it to select the cell with Text instead of numbers and the cell to the left of that cell so it can merge them... Here is the code I have for merging.


    Dim outputText As String
    Const delim = " "

    On Error Resume Next

    For Each cell In Selection
    outputText = outputText & cell.Value & delim
    Next cell
    With Selection
    .Clear
    .Cells(1).Value = outputText

    End With



    Any help would be great!

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Selecting cell that contains text and merging without data loss.

    Hi,

    Do you really need a macro. Why not a helper column with something like

    Formula: copy to clipboard
    Please Login or Register  to view this content.

    copied down. Then copy the helper column and use paste special values to overwrite the column H values.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    05-14-2015
    Location
    IOWA CITY, IOWA, USA
    MS-Off Ver
    2010
    Posts
    30

    Re: Selecting cell that contains text and merging without data loss.

    It is possible to do through other means, but rather than having to copy a column, merge a column by hand, delete a column, id much rather it just be part of the script I am running already

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Selecting cell that contains text and merging without data loss.

    Hi arpirnat,

    Try this:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  5. #5
    Registered User
    Join Date
    05-14-2015
    Location
    IOWA CITY, IOWA, USA
    MS-Off Ver
    2010
    Posts
    30

    Re: Selecting cell that contains text and merging without data loss.

    Getting an error in the last line. Application-Defined or Object-Defined

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Selecting cell that contains text and merging without data loss.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  7. #7
    Registered User
    Join Date
    05-14-2015
    Location
    IOWA CITY, IOWA, USA
    MS-Off Ver
    2010
    Posts
    30

    Re: Selecting cell that contains text and merging without data loss.

    Here is a small sample of the sheet.

    Thanks!
    Attached Files Attached Files

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Selecting cell that contains text and merging without data loss.

    This works on your sample:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    05-14-2015
    Location
    IOWA CITY, IOWA, USA
    MS-Off Ver
    2010
    Posts
    30

    Re: Selecting cell that contains text and merging without data loss.

    I have tried this on the sample as well and it works, I don't know what is killing it on the main sheet. The only difference in the main sheet vs. the sample is that the main sheet contains some rows that have nothing in any column except for A, and of course the overall size of course.

    If I step in to it no errors because it keeps cycling through the first part, it's just the last line that is giving an error.

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Selecting cell that contains text and merging without data loss.

    This works on your sample with one row having only an entry in A:

    Please Login or Register  to view this content.
    *You know arpirnat that if this doesn't work on the real data then we will need a better sample

  11. #11
    Registered User
    Join Date
    05-14-2015
    Location
    IOWA CITY, IOWA, USA
    MS-Off Ver
    2010
    Posts
    30

    Re: Selecting cell that contains text and merging without data loss.

    It is definitely bugging out on lines where there is only input in Column A and no others. Attached a new sample.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    05-14-2015
    Location
    IOWA CITY, IOWA, USA
    MS-Off Ver
    2010
    Posts
    30

    Re: Selecting cell that contains text and merging without data loss.

    I was able to figure out the problem and fix it by putting in On Error Resume Next. Thanks!

  13. #13
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Selecting cell that contains text and merging without data loss.

    Excellent, because the sample you sent last didn't fail - so, I would have still been in the dark

    You're welcome and thanks for the rep!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Merging Text with Numeric into One Cell
    By swalsh^s96 in forum Excel General
    Replies: 2
    Last Post: 04-13-2015, 04:36 PM
  2. [SOLVED] Selecting text and merging over x number of columns
    By coach.32 in forum Excel General
    Replies: 2
    Last Post: 03-08-2015, 02:34 AM
  3. [SOLVED] Trading Spreadsheet - Random win/loss outcome against established Win/Loss %
    By cruze2005 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-18-2014, 05:08 AM
  4. Loss of cell text when pasting
    By pogrady in forum Excel General
    Replies: 8
    Last Post: 06-28-2014, 03:17 AM
  5. Issue selecting and merging cells after a row insert
    By jkyle69 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-19-2014, 03:53 PM
  6. merging text and data fields with zeroes
    By bcaplan1940 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-31-2007, 04:03 AM
  7. Replies: 2
    Last Post: 05-09-2007, 06:34 AM

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