Solved

searching for a quote in VB

Posted on 2010-11-30
7
277 Views
Last Modified: 2012-05-10
I have a text like the following

ShowMessage("Hello World", "abc")

I try to extract the 'Hello World' text message out in VBA if  I see it is a function ShowMessage.  Of course that can be a space before and after '('.

I have right up a function to examine the function name, then open bracket, and then try to search for the double quote.  What I notice that the Mid(string, 1, 1) function will return me 'H' whether my string is "Hello" or Hello.  
Is there any way I can search for double quote.
Or some other mean to extract the text message.

Thanks.
0
Comment
Question by:tommym121
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34241597
I hope I have understood your query correctly. If not, then please ignore this post and let me know what exactly do you want...

Sub Sample()
    Dim strString As String
    
    strString = """" & "hello" & """"
    
    MsgBox strString
    MsgBox Mid(strString, 1, 1)
End Sub

Open in new window

0
 

Author Comment

by:tommym121
ID: 34241641
The problem, I have import this file with columns of this types of data. What do I do in that situation?
0
 
LVL 39

Expert Comment

by:nutsch
ID: 34241648
something like this?

Thomas
sub get quotes

Dim str As String
str = selection
str = Left(Mid(str, 1 + InStr(str, "(""")), InStr(Mid(str, 1 + InStr(str, "(""")), ""","))
debug.print str

end sub

Open in new window

0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 30

Assisted Solution

by:SiddharthRout
SiddharthRout earned 250 total points
ID: 34241669
May I see a sample file?
0
 
LVL 39

Expert Comment

by:nutsch
ID: 34241682
then for your whole selection:
Sub dgasdg()
Dim str As String, cl As range


For Each cl In selection.Cells

    If InStr(cl, "ShowMessage") > 0 Then _
        cl = Left(Mid(cl, 1 + InStr(cl, "(""")), InStr(Mid(cl, 1 + InStr(cl, "(""")), ""","))

Next

End Sub

Open in new window

0
 
LVL 14

Accepted Solution

by:
pteranodon72 earned 250 total points
ID: 34241687
Use InStr to find the position of the first doublequote character in a string. The doublequote character's ASCII code is 39.


Dim intPos as Integer
Dim strSearch as String

intPos = InStr(strSearch, chr(39))

If intPos = 0 Then
  Debug.Print "No double-quotes found in string"
Else
  Debug.Print "File double-quote found at position " & intPos & "."
End If

HTH,
pT72
0
 

Author Closing Comment

by:tommym121
ID: 34247696
Thanks.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question