ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Concatenating a string and an integer (https://www.excelbanter.com/excel-programming/358103-concatenating-string-integer.html)

[email protected]

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


K Dales[_2_]

Concatenating a string and an integer
 
Just use Trim:
CellRefer = "B" & Trim(Str(RptRowCounter))
--
- K Dales


" 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

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)




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


All times are GMT +1. The time now is 04:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com