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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
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,213,506
Messages
6,114,024
Members
448,543
Latest member
MartinLarkin

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