Working with Strings

Philosophaie

Active Member
Joined
Mar 5, 2010
Messages
256
I want to know how to make a double quote, ", appear in a string of characters so I can use them in my VBA code.

Dim cell1 as Range
Dim cell2 as Range
Dim VBArange as String
cell1="A4"
VBAstring = "Range(" & """ & cell1 & """ & ")=1"

obviously the """ does not work. What I am looking for is a replacement to display the " in the Range.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
What is the resulting string supposed to be?
 
Upvote 0
Code:
    Dim s As String
    Dim cell As Range
    
    Set cell = Range("A4")
    s = "Range(""" & cell.Address(False, False) & """)"
    MsgBox s
 
Upvote 0
Or

Code:
Sub test1()
    Dim VBArange As String, cell1 As String
    cell1 = "A4"
    VBArange = "Range(" & """" & cell1 & """" & ")=1"
    MsgBox VBArange
End Sub

M.
 
Upvote 0
I don't mind the doubled, tripled, quadrupled quotes and so on but some prefer using the Chr() function, so another variation on the theme is:

VBAstring = "Range(" & Chr(34) & cell1 & Chr(34) & ")=1"

this is always a good one in a pinch and probably makes code easier to read in some cases.
 
Upvote 0
I had to use CStr(cell1) to get it to work but I keep getting "Error 2015" when a function is in the cell. Any thoughts?
 
Upvote 0
What's the complete function you are using?
ξ
 
Upvote 0
=Function1(B2, C2, D2)

The function works. It gives the correct number result from row 2 columns B,C,D.

It just gives the "Error 2015" when converted to a string!
 
Last edited:
Upvote 0
Code:
=Function1(B2, C2, D2)

This is what's in the cell, but what is Function1 ... ?
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,351
Members
452,907
Latest member
Roland Deschain

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