Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

how to include double quote in string

  Asked By: Ella    Date: Sep 17    Category: MS Office    Views: 948
  

I need to compare two strings, and the strings contain double quotes.
How do I made the below codes work?

mystr = "=========I Love "VBA"=========="
newstr = "-----------love "VBA"----------"

if strcomp(mystr, newstr) <> 0 then
newstr = mystr
end if

Share: 

 

8 Answers Found

 
Answer #1    Answered By: Isabelle Brown     Answered On: Sep 17

Two ways come to mind:
1) You can use double  double quotes, as follows: mystr = "=========I
Love ""VBA""===============" - although I might have the format
incorrect, the idea is correct.
2) Programmatically find and replace all "VBA" with _VBA_, do your
comparison, and replace _VBA_ with "VBA" before reporting. May sound
long-winded, but for me at least, much easier than the first.

 
Answer #2    Answered By: Nagaraju Iyaner     Answered On: Sep 17

I knew the double  double quotes  way...however, somehow, it doesn't
work for string  that contants _ inside the double code, such
as "ABC_abc"...I bet I have to recheck my code to see what the real
problem is...If I can't find the problem, then I will try your second
method.

 
Answer #3    Answered By: Tyrone Sanchez     Answered On: Sep 17

I needed VBA code to return the column number of a cell with a string.
Like, If I have entered "First assign time" in A1, the code has to return the
column number as 1.

 
Answer #4    Answered By: Jonathan Brown     Answered On: Sep 17

Hope this is what you are looking for.
Range("A1").Column

 
Answer #5    Answered By: Husani Chalthoum     Answered On: Sep 17

But, can't we search it based on the string  itself?
Like Range("Find the assign time").column.?
I tried this method, but it did not work.
The string might be anywhere in the worksheet and code has to return just the
column number.

 
Answer #6    Answered By: Jared Adams     Answered On: Sep 17

Yes we can do, but when you are naming a cell or range it should not contain
any space in between.
Use Range("Find_Assign_Time").Column will return column number of the first
cell of the defined table.

 
Answer #7    Answered By: Tarrant Thompson     Answered On: Sep 17

Function WhichColumn(myStr)
Application.Volatile 'can remove if not using
'this function as a worksheet function
Set dd = Cells.Find(What:=myStr, After:=Cells(Cells.Rows.Count, _
Cells.Columns.Count), LookIn:=xlValues, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not dd Is Nothing Then WhichColumn = _
dd.Column Else WhichColumn = "Not found"
End Function

Use in a worksheet formula thus:

=WhichColumn("First assign time")

and in vba  code thus:

x = WhichColumn("First assign time")

or

y = "First Assign time"
x= WhichColumn(y)

 
Answer #8    Answered By: Janelle Evans     Answered On: Sep 17

Not
a named range, but to search for the string  inside the cell, is that right?

 
Didn't find what you were looking for? Find more on how to include double quote in string Or get search suggestion and latest updates.




Tagged: