Referring to Cells in Excel

Hello experts,
How can I create the following strings in VB ?

c11
c12
c13
c14
c15
...

?
I can not do a Do While loop using "C" + counter because one is a string and the other is an integer.
Sorry for posting a silly question. I had the same problem in Access and it worked to do a Me("C" & i) but that does not work here.
Thanks
MannsiAsked:
Who is Participating?
 
zorvek (Kevin Jones)Connect With a Mentor ConsultantCommented:
Dim Row As Long
For Row = 11 To 60
    SendQuery "C" & Row, "...", "..."
Next Row

Kevin
0
 
zorvek (Kevin Jones)ConsultantCommented:
Assuming you have a worksheet object, treat the columns as an integer (C = 3) and use the Cells object:

   TargetWorksheet.Cells(Row, Column)

Kevin
0
 
DaveCommented:
Can you pls expand on your question - it is not apparent what you are wanting to do with these strings, and how Excel fits in

Regards

Dave
0
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.

 
MannsiAuthor Commented:
I've got a few SQL queries that I run in VB, each giving me a single result. I then "paste" the results of the queries in Excel. The strings are supposed to guide VB to where the results should go. They need to be strings because the function that prints the result of the query says so.
0
 
zorvek (Kevin Jones)ConsultantCommented:
Then you can use the Range method:

   TargetWorksheet.Range("C1") = Recordset!Field1

Kevin
0
 
MannsiAuthor Commented:
I don't have a recordset, I use the below function.


Sub SendQuery(sDestRange As String, sODBC As String, sSQL As String)
    With ActiveSheet.QueryTables.Add(Connection:=sODBC,    Destination:=Range(sDestRange))
        .Sql = sSQL
        .FieldNames = False
        .RefreshStyle = xlInsertDeleteCells
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .RefreshOnFileOpen = False
        .HasAutoFormat = False
        .BackgroundQuery = True
        .TablesOnlyFromHTML = True
        .Refresh BackgroundQuery:=False
        .SavePassword = True
        .SaveData = True
    End With
End Sub

Open in new window

0
 
zorvek (Kevin Jones)ConsultantCommented:
And you need to determine how to set sDestRange? Use a simple string:

   SendQuery "C1", "...", "..."

Kevin
0
 
MannsiAuthor Commented:
Yeah, but I have a loop for the SQL query that would be very nice to be able to use for the sDestRange instead of having to write the whole thing 50 times.
0
 
mikainzCommented:
you can convert a integer into a string type by using the STRING function
0
 
MannsiAuthor Commented:
lol, didn't try doing a "c" & i for my strings, just assumed that since "c" + i didn't work, neither would the other one. Thanks for the answer.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.