Excel VBA copy contents of cells A1:A22 to string variable

gustaf111

Board Regular
Joined
Sep 6, 2011
Messages
120
Hello all,

I would like to copy the contents of cells A1 to A22 to a string variable. The cell are not merged becuase I would like to design the contents better (there are several rows).

Ex:

A B C D E .....
1 Hello World

The string I would like to have is:
String = Hello World

Cheers Gustaf
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Maybe like this

Code:
Sub test4()
Dim s As String
s = Join(Application.Transpose(Range("A1:A22")), " ")
MsgBox s
End Sub
 
Upvote 0
Thanks VoG!

I would like also to have all cells on a row, but it does not work just to replace with:

s = Join(Application.Transpose(Range("A1:G1")), " ")

:(
 
Upvote 0
Try

Code:
Sub test4()
Dim s As String
s = Join(Application.Transpose(Application.Transpose(Range("A1:G1"))), " ")
MsgBox s
End Sub
 
Upvote 0
Re: Excel VBA copy contents of cells A1:W1 to string variable

The code does not exactly what I want, I try to explain:

I would like to get a string of all columns from column A1 to W1. But these to strings will not be the same:

1) If I start the input on column A1 and add spaces to column F1 and there write hello.

2) If I start the input on column F1 and write hello.

String number 1 will look like:
B1
hello (not correct postion, should be there string number 2 is)

string number 2 will look lime:
F1
hello (correct position)

Please Help!
Cheers Gustaf
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,901
Members
452,948
Latest member
Dupuhini

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