+ Reply to Thread
Results 1 to 6 of 6

Create text from multiple cells/ranges

  1. #1
    Registered User
    Join Date
    05-10-2008
    Posts
    18

    Create text from multiple cells/ranges

    I realize the answer for this probably rather simple, but I ask you bare with me as I jump into Excel/VBA programming for the first time...

    I am trying to create a VBA script that will take data from individual cells or a range of cells (ie. A1, B2, C3, D4, E5-E8) and create strings of text that it then copies to the clipboard. For example, let's say the above cell values are:

    A1: 3.14159
    B2: $2.00
    C3: 12
    D4: 5
    E5: Sue
    E6: Tom
    E7: Billy
    E8: Joe

    And I want the text that is copied to the clipboard when I press a button to read:

    "Tom found $2.00. Billy and Sue discovered the value of pi was 3.14159, and Joe found 17 marbles."

    (17 = C3+D4)

    So far, I've found that:

    Please Login or Register  to view this content.
    is basically what I need, but I can't seem to figure out the xxxxxx where the string is assigned to MyData.

    Thanks in advance!
    Last edited by VBA Noob; 05-10-2008 at 04:53 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You need to build your string like this
    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    05-10-2008
    Posts
    18
    Thanks!

    Now, what if I wanted to add a line break? As in:

    "Tom found $2.00. Billy and Sue
    discovered the value of pi was
    3.14159, and Joe found 17 marbles."

  4. #4
    Registered User
    Join Date
    05-10-2008
    Posts
    18
    I tried it precisely as you said and I keep getting the following error:

    Run-time error '438':
    Object doesn't support this property or method

    I even tried the sample input I gave above in a test sheet with precisely the code provided and got the same error. Is there a syntactical error somewhere?

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You need a reference set in your VBA project to the Microsoft Forms 2.0 object'

    In the VB Editor Tools menu slect References, scroll to find Microsoft Forms 2.0 . Select it & click OK.

    Next paste this code to a Standard Module

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    05-10-2008
    Posts
    18
    Works beautifully, 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