ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Simple VBA - What's wrong?? (https://www.excelbanter.com/excel-programming/284615-simple-vba-whats-wrong.html)

ChrisB[_3_]

Simple VBA - What's wrong??
 

Here's my sub-procedure, I am getting the error
message "Subscript out of range". Please help, I am only
wanting to set the cells value to a variable.

Public Sub TEST()
Dim strCellTest As String

sCellTest = Worksheets("Sheet1").Cells(1, 1).Value
Debug.Print sCellTest

End Sub

Also, how do I SET a cells value? Like this?:

Worksheets("Sheet1").Cells(1, 1).Value = strNewVal

Thanks in advance,

ChrisB


Chip Pearson

Simple VBA - What's wrong??
 
Chris,

Are you sure you have a worksheet named "Sheet1"?


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"ChrisB" wrote in message
...

Here's my sub-procedure, I am getting the error
message "Subscript out of range". Please help, I am only
wanting to set the cells value to a variable.

Public Sub TEST()
Dim strCellTest As String

sCellTest = Worksheets("Sheet1").Cells(1, 1).Value
Debug.Print sCellTest

End Sub

Also, how do I SET a cells value? Like this?:

Worksheets("Sheet1").Cells(1, 1).Value = strNewVal

Thanks in advance,

ChrisB




Gerrit

Simple VBA - What's wrong??
 

"ChrisB" schreef in bericht
...

Here's my sub-procedure, I am getting the error
message "Subscript out of range". Please help, I am only
wanting to set the cells value to a variable.

Public Sub TEST()
Dim strCellTest As String

sCellTest = Worksheets("Sheet1").Cells(1, 1).Value
Debug.Print sCellTest

End Sub

Also, how do I SET a cells value? Like this?:

Worksheets("Sheet1").Cells(1, 1).Value = strNewVal

Thanks in advance,

ChrisB


Are you sure Sheet1exist????????



Bob Phillips[_6_]

Simple VBA - What's wrong??
 
Chris,

Do you have worksheet called Sheet1?

By the way, you dimension a variable called strCellTest, and then use
sCellTest. Precede your code with Option Explicit!

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"ChrisB" wrote in message
...

Here's my sub-procedure, I am getting the error
message "Subscript out of range". Please help, I am only
wanting to set the cells value to a variable.

Public Sub TEST()
Dim strCellTest As String

sCellTest = Worksheets("Sheet1").Cells(1, 1).Value
Debug.Print sCellTest

End Sub

Also, how do I SET a cells value? Like this?:

Worksheets("Sheet1").Cells(1, 1).Value = strNewVal

Thanks in advance,

ChrisB





All times are GMT +1. The time now is 03:40 PM.

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