Excel VBA assign a range to a string variable.

eduzs

Well-known Member
Joined
Jul 6, 2014
Messages
704
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Hi there!
How to use Excel VBA to assign a range to a string variable, so I get only plain text.
Thanks
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
You cannot assign a "Range" to a String variable, you set it to a "Range Variable", like this:
VBA Code:
Dim myRange as Range
Set myRange= Range("A1:A100")

Or do you mean setting a String variable equal to the value in a particular cell, like this:
VBA Code:
Dim myVal as String
myVal = Range("A1").Value

If neither of those things, please explain in more detail. Maybe walk us through an actual example of what you want to do.
 
Upvote 0
When I copy a range (CTRL+C) and paste in Word (CTRL+V) I get a table, I want to get plain text instead without using pastespecial/pastevalues.
SO I want to set a string variable with this range plain text so I can put in clipboard.

Ps. I solved this using:

VBA Code:
Dim sTxt As String

Selection.Copy
sTxt = GetClipboard()
SetClipboard (sTxt)

GetCLipboard/SetClipboard I found elsewhere.

Thanks.
 
Upvote 0
When I copy a range (CTRL+C) and paste in Word (CTRL+V) I get a table, I want to get plain text instead without using pastespecial/pastevalues.
SO I want to set a string variable with this range plain text so I can put in clipboard.
That is some really important detail that you want to be sure to include in your request. Don't skimp on details when posting your question. The better the question, the better the help you will get. Seeing what you are talking about, I am not sure that I am going to be able to help you (in which case, I wouldn't have replied, and it would have still appeared as an Unanswered thread").

If I get a better of what you are trying to do, I may be able to offer some other solutions.
Can you show us an example of what your data may look like, and show us how exactly you want it to look in Word?
What is the purpose of this? Is it something that might be done better with a Mail Merge?
 
Upvote 0
The purpuse is when I copy and paste (ctrl+c ctrl+v) from excel to Whatsapp web I get an image, but I want to paste it as text, to do that, before I paste in zap, I need to paste in notepad, and then copy to zap web.
Now I can put the range in plain text in clipboard, not a table, not an image.
Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,830
Messages
6,181,227
Members
453,025
Latest member
Hannah_Pham93

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