ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Reference Cell # with variable (https://www.excelbanter.com/excel-programming/382039-reference-cell-variable.html)

SJW

Reference Cell # with variable
 
Need help with the code below.
If I substitute
CellContents = Worksheets("Data for Sim RT").[B100].Text
It works!

Sub TestCellVariable()
Dim CellContents As Variant '...Cell contents
Dim lngCellNum As Long '...Row number
Dim strCell As Variant

lngCellNum = 100

strCell = "B" & lngCellNum
CellContents = Worksheets("Data for Sim RT").[strCell].Text

MsgBox "zzz Cell Contents is " & CellContents

End Sub

Niek Otten

Reference Cell # with variable
 
CellContents = Worksheets("Data for Sim RT").Range(strCell).Text

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"sjw" wrote in message ...
| Need help with the code below.
| If I substitute
| CellContents = Worksheets("Data for Sim RT").[B100].Text
| It works!
|
| Sub TestCellVariable()
| Dim CellContents As Variant '...Cell contents
| Dim lngCellNum As Long '...Row number
| Dim strCell As Variant
|
| lngCellNum = 100
|
| strCell = "B" & lngCellNum
| CellContents = Worksheets("Data for Sim RT").[strCell].Text
|
| MsgBox "zzz Cell Contents is " & CellContents
|
| End Sub



SJW

Reference Cell # with variable
 
Perfect!

Thanks,
sjw

"Niek Otten" wrote:

CellContents = Worksheets("Data for Sim RT").Range(strCell).Text

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"sjw" wrote in message ...
| Need help with the code below.
| If I substitute
| CellContents = Worksheets("Data for Sim RT").[B100].Text
| It works!
|
| Sub TestCellVariable()
| Dim CellContents As Variant '...Cell contents
| Dim lngCellNum As Long '...Row number
| Dim strCell As Variant
|
| lngCellNum = 100
|
| strCell = "B" & lngCellNum
| CellContents = Worksheets("Data for Sim RT").[strCell].Text
|
| MsgBox "zzz Cell Contents is " & CellContents
|
| End Sub





All times are GMT +1. The time now is 09:56 AM.

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