Solved

String size in Excel VBA

Posted on 2015-01-04
7
99 Views
Last Modified: 2015-01-06
I have a string that contains a long SQL structure for retrieving data from SQL Server. Is there a work around solution to have longer string size to contain this long statement ?

Tks
0
Comment
Question by:AXISHK
  • 3
  • 3
7 Comments
 
LVL 27

Accepted Solution

by:
MacroShadow earned 200 total points
ID: 40530985
Use line continuations to split your statement into multiple lines. i.e.
strSQL = "Use line continuations" _
         & "to split your statement" _
         & "into multiple lines"

Open in new window

0
 

Author Comment

by:AXISHK
ID: 40530999
Seem like there is a size limitation in string strSQL, correct ?
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 40531002
About 2 billion characters. I seriously doubt you're even close to that limit.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 300 total points
ID: 40531565
There is a limit on the number of lines that can be continued

You may have to use string concatenation.
Example:
strSQL = "Select * "
strSQL = strSQL & "From mytable "
strSQL = strSQL & "Where fieldname = 42"

Open in new window


You could also read the SQL string from a file source.

================
Are you trying to store the SQL in an Excel cell?
0
 

Author Comment

by:AXISHK
ID: 40532550
The SQL statement is coded in a VBA. Any better way to handle this ?

For string size, it is not limited to 255 chars, correct ?

Tks
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 40532906
Coding the string in VBA is fine as long as the lines are not too long (use line continuations or string concatenation).
String size isn't limited to 255 chars.
0
 

Author Closing Comment

by:AXISHK
ID: 40534876
Tks
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

776 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