VBA to concatenate data

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
I have a table on sheet1 named Table1 (it starts in A10)

My first column my users go through each row and where they want to use the data they put an "X"

Is there a way to use VBA to due a Next type of statement where when there is an X in column A it takes the values in column B and concatenates them all and puts them into cell B2 (my table starts in A10)
I need enclose each item in { } so if I need to parse the data later I can.

Thanks for the help.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
An example of your data and what result you want would be helpful. Trying to guess what you want, but not VBA (used a formula in B2) I tried this:

Book32
AB
2{Two}{Three}{Six}
3
4
5
6
7
8
9
10MarkData
11One
12xTwo
13xThree
14Four
15Five
16xSix
17Seven
Sheet3
Cell Formulas
RangeFormula
B2B2=MarkRow()


Code:
Function MarkRow()
Dim str As String, lr As Long, i As Long
str = "{"
lr = Cells(Rows.Count, "A").End(xlUp).Row
For i = 11 To lr
 If "x" = Cells(i, "A") Then
   str = str & Cells(i, "B") & "}{"
 Else
 End If
Next i
MarkRow = Left(str, Len(str) - 1)
End Function
 
Upvote 0
Solution

Forum statistics

Threads
1,215,133
Messages
6,123,233
Members
449,092
Latest member
SCleaveland

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top