+ Reply to Thread
Results 1 to 2 of 2

store contents of entire column as string

Hybrid View

  1. #1
    Registered User
    Join Date
    04-19-2010
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    40

    Post store contents of entire column as string

    Hi everyone,

    my vba skills are limited as i am just starting to learn, what i am trying to do is get my script to store contents of every cell in column H (separated by a new line) as a string.

    this is so that i can then pass this string to a new outlook appointment.

    that is, lets assume column H looks like this

    H
    1 Title
    2 ITEM1
    3 ITEM2
    4 ITEM3
    5 ITEM4
    6 ITEM5
    7 ITEM6
    8 ITEM7

    i would like ITEM1 and onwards down the column to be stored in one string

    your help would be greatly appreciated.

  2. #2
    Forum Contributor wamp's Avatar
    Join Date
    11-10-2008
    Location
    Norway
    MS-Off Ver
    97, 2000 & 2003 (diff. workstations)
    Posts
    184

    Re: store contents of entire column as string

    Place attached code in a module
    NOTE! a string it self does have a limit to number of characters, so if you have a LOT of items, you should concider another approach.

    tip: if you're just starting to learn VBA, I suggest that you set a breakpoint at "Sub toClipboard" (F9)
    then start the macro and hit F8 for each line of code. - Then you'll see what each line does and you will learn a lot. (you can even mouse over variables to see what their content is.)

    Sub toClipboard()
    Dim rNum As Integer  ' rownumber
    Dim toclip As String ' to clipboard (your string)
    
    Range("H2").Select  ' first selection as H1 contains the title
    rNum = 2
    
    nxt:   ' start of loop proccess
    If ActiveCell.Value = "" Then GoTo finish ' if there is nothing in the cell, end this proccess
    toclip = toclip & " " & ActiveCell.Value  ' add a space in between and then the activecell content to your string
    rNum = rNum + 1 ' add a number to rNum so it will check the next row
    Range("H" & rNum).Select ' select next cell based on rNum
    GoTo nxt ' go back to loop start
    finish:
    
    
    'Your code for the string you've made goes here
    MsgBox (toclip)  ' for checking purpouses. comment out this after use
    
    
    End Sub
    Last edited by wamp; 04-20-2010 at 01:50 AM.

+ 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