+ Reply to Thread
Results 1 to 6 of 6

Adding a string to each cell in a selection

  1. #1
    Registered User
    Join Date
    07-15-2015
    Location
    Amsterdam
    MS-Off Ver
    Office 2010
    Posts
    4

    Adding a string to each cell in a selection

    Hello everyone,

    what I am trying to do: copy-paste a range of cells (they all contain strings) from one workbook to another ADDING a piece of string (always the same) to every cell in range.

    Example:
    Original cell content:

    Sun
    Is
    Shining


    Copied and modified cell content:
    Sun_1
    Is_1
    Shining_1




    What I did: the first solution I tried, in an example, is the following

    1) Copy-paste the range
    2) select the newly copied range
    3) modify it

    The code looks like this, and it works:

    Please Login or Register  to view this content.

    Now, if I move this solution to my main macro the code does not work.

    Please Login or Register  to view this content.
    Of course, all the variables have been declared before (dataSheet, dataRow, localFile, etc...). In fact, if I remove the last 4 rows of code the macro works perfectly fine so I am sure that the problem comes from the way I am doing this.

    Being a beginner, I am assuming I am messing around in the wrong way with objects, methods and the like but I cannot figure out what is the problem.

    FYI: the error I get when running the macro is: "Select Method of Range class failed".

    Google tells me that this has something to do with changing sheets too many times, but I cannot find solution.

    Thanks a lot for the help,

    Konx

  2. #2
    Forum Contributor
    Join Date
    08-04-2014
    Location
    Riga
    MS-Off Ver
    2010
    Posts
    579

    Re: Adding a string to each cell in a selection

    I only noticed that you do not have ELSE or END IF, not sure if that changes anything.

  3. #3
    Forum Contributor
    Join Date
    08-04-2014
    Location
    Riga
    MS-Off Ver
    2010
    Posts
    579

    Re: Adding a string to each cell in a selection

    Just to change the text, I would do this (EndNumber is the total amount of rows you have):

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Adding a string to each cell in a selection

    Does this help?

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-15-2015
    Location
    Amsterdam
    MS-Off Ver
    Office 2010
    Posts
    4

    Re: Adding a string to each cell in a selection

    Thank you JOHN and bmouse, problem solved

    This forum is amazingly good and fast!

    Konx

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Adding a string to each cell in a selection

    You're welcome. Glad to help out and thanks for the feedback.

+ 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. [SOLVED] How to find a number in a string and copy it to the cell below while adding 1 to it
    By GreenTee in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-05-2015, 03:43 PM
  2. Calculating/adding userform textbox values based on combobox selection and display to cell
    By SpreadsheetGirl in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-04-2015, 08:57 AM
  3. [SOLVED] adding to end of string based on another cell getting changed
    By hopefulhart in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-07-2014, 04:37 AM
  4. adding a cell in a text string
    By seemore in forum Excel General
    Replies: 11
    Last Post: 08-13-2009, 04:31 AM
  5. Adding(Append) fix string before a particular cell
    By prayami in forum Excel General
    Replies: 1
    Last Post: 01-02-2008, 05:29 PM
  6. Search dynamic selection and delete cell string
    By Andy748 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-11-2007, 02:33 AM
  7. adding a string prefix/suffix to a cell
    By elroy in forum Excel General
    Replies: 4
    Last Post: 03-08-2007, 04:47 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