Do while VB Macro

sanj_shah

New Member
Joined
Apr 10, 2005
Messages
15
Hi,

I have a worksheet like below:

I have separated each column with a comma below for the layout in this post ie.
column1,column2,column3

aaa1,bb1,ccc1
, ,ccc2
, ,ccc3
, ,ccc4
, ,ccc5
,bb2,ccc1
, ,ccc2
, ,ccc3
, ,ccc4
,bb3,ccc1
, ,ccc2
, ,ccc3
aaa2,bb1,ccc1
, ,ccc2
, ,ccc3
, ,ccc4
, ,ccc5
,bb2,ccc1
, ,ccc2
, ,ccc3
, ,ccc4
aaa3,bb1,ccc1
, ,ccc2
, ,ccc3
, ,ccc4
, ,ccc5

etc

what I would like is to create the following value to be pasted into another
cell (i.e. A1000)

aaa1=["bb1","ccc1","ccc2","ccc3","ccc4","ccc5","bb2","ccc1","ccc2","ccc3","c
cc4","bb3","ccc1","ccc2","ccc3"]&aaa2=["bb1","ccc1","ccc2","ccc3","ccc4","cc
c5","bb2","ccc1","ccc2","ccc3","ccc4"]&aaa3=["bb1","ccc1","ccc2","ccc3","ccc
4","ccc5"];

I tried to use the do while loop but cannot get this to work, could someone
please point me in the right direction.

Thanks!

Sanj
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Give this a try:

Code:
Sub test()
Dim x As Long, tmp As String
For x = 1 To Range("C65536").End(xlUp).Row + 1
    If Range("A" & x) <> "" Then tmp = tmp & "&" & Range("A" & x) & "=["
    If Trim(Range("B" & x)) <> "" Then tmp = tmp & Chr(34) & Trim(Range("B" & x)) & Chr(34) & " "
    If Trim(Range("C" & x)) <> "" Then tmp = tmp & Chr(34) & Trim(Range("C" & x)) & Chr(34) & " "
    If Range("A" & x).Offset(1, 0) <> "" Then tmp = tmp & "]"
Next x
tmp = Replace(Replace(Application.Trim(tmp), " ", ", "), ", ]", "]") & "];"
Range("A1000") = tmp
End Sub
 
Upvote 0

Similar threads

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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