+ Reply to Thread
Results 1 to 4 of 4

concatenating integer and string

Hybrid View

  1. #1
    Registered User
    Join Date
    03-29-2010
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    70

    concatenating integer and string

    testRev2.xlsm

    I've written a module (below and also in the attached excel file) to read a series of *.csv files (which I access online) and insert into a spreadsheet. I'm kind of stuck on some basic VBA syntax, specifically, how to concatenate the string "C" with the integer I, to form a string which can then define 'qrow' which is the cell location to write each line of data to. Any insights would be greatly appreciated. Thanks!

    
    Sub GetData()
    
        Dim QuerySheet As Worksheet
        Dim DataSheet As Worksheet
        Dim qurl As String
        Dim qrow As String
        Dim i As Integer
            
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
        Application.Calculation = xlCalculationManual
        
        i = 128
        Set DataSheet = ActiveSheet
        Range("C7").CurrentRegion.ClearContents
        qurl = Cells(i, 14)
        
        For i = 128 To 7 Step -1
           qrow = "C" + string(i)
    
    QueryQuote:
                With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=DataSheet.Range("qrow"))
                    .BackgroundQuery = True
                    .TablesOnlyFromHTML = False
                    .Refresh BackgroundQuery:=False
                    .SaveData = True
                End With
                
                Range("qrow").CurrentRegion.TextToColumns Destination:=Range("qrow"), DataType:=xlDelimited, _
                    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
                    Semicolon:=False, Comma:=True, Space:=False, other:=False
                    
        Next i
        
    End Sub
    basically, I'm looping from row 128 to row 7 in the excel file and trying to write the downloaded data to cell location C128, C127... C7.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: concatenating integer and string

    With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=DataSheet.Cells(i, "C")
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: concatenating integer and string

           'Try this...
           qrow = "C" & i
           'Then reference like this...
           Range(qrow)
           
           'Or just...
           Range("C" & i)
           'or
           Cells(i, "C")

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: concatenating integer and string

    To do the concatenation you would use this.
    qrow = "C"& i
    However, shg shows a better way.
    If posting code please use code tags, see here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1