Solved

searching for a quote in VB

Posted on 2010-11-30
7
275 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

929 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now