Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop through range and add each cell contents to a string
Hi there,
Say I have a range A1:A100. How, when clicking a command button, do I get excel to loop through the range adding the contents into a string with a colon between each entry? e.g. A 1 2 3 4 Becomes ;pete@pete .com" Many thanks, David |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop through range and add each cell contents to a string
dim myRange as range, r as range
dim aWS as worksheet Dim myString as string set aWS = activesheet myString = "" set myRange = aWS.range("A1:A100") for each r in myrange if not isempty(r) then mystring = mystring & ";" & r.value end if next r next r "Daveo" wrote: Hi there, Say I have a range A1:A100. How, when clicking a command button, do I get excel to loop through the range adding the contents into a string with a colon between each entry? e.g. A 1 2 3 4 Becomes ;pete@pete .com" Many thanks, David |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop through range and add each cell contents to a string
Maybe something like this:
Paste this code into a General Module Note: change the "MySheet" reference to the name of your worksheet. '-------Start of Code--------------- Sub BuildEmailString() Dim rCell As Range Dim strText As String If MsgBox(Title:="IMPORTANT", _ Prompt:="This program inserts the email list in the active cell." _ & vbCr & vbCr & "OK to continue?", _ Buttons:=vbQuestion + vbYesNo) _ = vbNo Then Exit Sub End If strText = "" For Each rCell In Worksheets("MySheet").Range("A1:A100").Cells If InStr(1, rCell.Text, "@") 0 Then strText = strText & rCell.Text & ";" End If Next rCell ActiveCell.Value = Left(strText, Len(strText) - 1) End Sub '-------End of Code--------------- Is that something you can work with? *********** Regards, Ron XL2002, WinXP "Daveo" wrote: Hi there, Say I have a range A1:A100. How, when clicking a command button, do I get excel to loop through the range adding the contents into a string with a colon between each entry? e.g. A 1 2 3 4 Becomes ;pete@pete .com" Many thanks, David |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop through range and add each cell contents to a string
Thanks folks - got it sorted with your help!
David |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro to clear range contents when cell contents are changed by us | Excel Programming | |||
Loop through range of cells, string search, take action | Excel Programming | |||
Display contents of cell in another cell as part of text string? | New Users to Excel | |||
IF Cell Contents Start with STRING | Excel Worksheet Functions | |||
How easy is it to loop in VBA based on cell contents? | Excel Worksheet Functions |