+ Reply to Thread
Results 1 to 3 of 3

Concatenating a string and an integer

  1. #1

    Concatenating a string and an integer

    Hi,

    I am trying to move down a column by varying a counter for the row.
    Whether I use "B" & Str(RptRowCounter) or "B" + Str(RptRowCounter), the
    resulting string is B 5. As a result, Range(B 5).Value is giving me
    errors.

    How do I avoid the blank in between so that I get B5?

    Dim RptName As String
    Dim RptRowCounter As Integer
    Dim CellRefer As String

    RptRowCounter = 5
    CellRefer = "B" & Str(RptRowCounter)
    RptName = Range(CellRefer).Value

    Thanks for your help.
    Aswini


  2. #2
    K Dales
    Guest

    RE: Concatenating a string and an integer

    Just use Trim:
    CellRefer = "B" & Trim(Str(RptRowCounter))
    --
    - K Dales


    "[email protected]" wrote:

    > Hi,
    >
    > I am trying to move down a column by varying a counter for the row.
    > Whether I use "B" & Str(RptRowCounter) or "B" + Str(RptRowCounter), the
    > resulting string is B 5. As a result, Range(B 5).Value is giving me
    > errors.
    >
    > How do I avoid the blank in between so that I get B5?
    >
    > Dim RptName As String
    > Dim RptRowCounter As Integer
    > Dim CellRefer As String
    >
    > RptRowCounter = 5
    > CellRefer = "B" & Str(RptRowCounter)
    > RptName = Range(CellRefer).Value
    >
    > Thanks for your help.
    > Aswini
    >
    >


  3. #3
    Dave Peterson
    Guest

    Re: Concatenating a string and an integer

    Excel is pretty nice:
    cellrefer = "B" & rptrowcounter

    Or you could drop the CellRefer completely:

    rptname = cells(rptrowcounter,"B").value

    (and you may want to dim RptRowCount as Long--for those large numbered rows)




    [email protected] wrote:
    >
    > Hi,
    >
    > I am trying to move down a column by varying a counter for the row.
    > Whether I use "B" & Str(RptRowCounter) or "B" + Str(RptRowCounter), the
    > resulting string is B 5. As a result, Range(B 5).Value is giving me
    > errors.
    >
    > How do I avoid the blank in between so that I get B5?
    >
    > Dim RptName As String
    > Dim RptRowCounter As Integer
    > Dim CellRefer As String
    >
    > RptRowCounter = 5
    > CellRefer = "B" & Str(RptRowCounter)
    > RptName = Range(CellRefer).Value
    >
    > Thanks for your help.
    > Aswini


    --

    Dave Peterson

+ 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