Building A string

D

dmoney

I have a need to build a string that is a concantanation of and undetermined
amonunt of addresses. For example my code finds an initial address of a cell
and stores it to a variable. my code then performs a find next to get the
next address and i would like to build on to the initial string for every new
address with a desired final string something similar to this "=$a$13 & "+" &
$a$23 & "+" & $a$613 & "+" & $c$733 ...

basically im trying to build a string to put in a cell that will add the
values of certain cells based on a condition

your help is greatly appreciated
 
J

Jacob Skaria

The below macro will take you in the right direction..

Sub Macro1()
Dim varFound As Variant, varSearch As Variant
Dim strAddress As String, strOutput As String

varSearch = "dmoney"
With Worksheets("Sheet1").UsedRange
Set varFound = .Find(varSearch, LookIn:=xlValues)
If Not varFound Is Nothing Then
strAddress = varFound.Address
Do
Set varFound = .FindNext(varFound)
strOutput = strOutput & "+" & varFound.Address
Loop While Not varFound Is Nothing And _
varFound.Address <> strAddress
End If
End With
MsgBox "=" & Mid(strOutput, 2)
End Sub

If this post helps click Yes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top