ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   ActiveCell giving blank value in vbscript (https://www.excelbanter.com/excel-worksheet-functions/43071-activecell-giving-blank-value-vbscript.html)

itstome

ActiveCell giving blank value in vbscript
 

I am having the following code:

oSheet.Cells(2,3).Select
msgbox oSheet.Cells(2,3).value
Msgbox ActiveCell.Value

The cell is having value, but still, its giving the following error:
Error Description: Object Required 'ActiveCell'

i did the following also:
msgbox activecell

but its giving me a blank messagebox

Please someone help me out in this . Thanks in advance


--
itstome
------------------------------------------------------------------------
itstome's Profile: http://www.excelforum.com/member.php...o&userid=26787
View this thread: http://www.excelforum.com/showthread...hreadid=400413


Bernie Deitrick

Most likely, the activecell is blank, since you cannot change the selection on an inactive sheet.
Activecell refers to the selection on the activesheet, so you need to activate your sheet prior to
selecting:

Dim oSheet As Worksheet
Set oSheet = Worksheets("Sheet1")
oSheet.Activate
oSheet.Cells(2, 3).Select
MsgBox oSheet.Cells(2, 3).Value
MsgBox ActiveCell.Value


But your code need not rely on Activecell:

Dim oSheet As Worksheet
Set oSheet = Worksheets("Sheet1")
MsgBox oSheet.Cells(2, 3).Value

HTH,
Bernie
MS Excel MVP


"itstome" wrote in message
...

I am having the following code:

oSheet.Cells(2,3).Select
msgbox oSheet.Cells(2,3).value
Msgbox ActiveCell.Value

The cell is having value, but still, its giving the following error:
Error Description: Object Required 'ActiveCell'

i did the following also:
msgbox activecell

but its giving me a blank messagebox

Please someone help me out in this . Thanks in advance


--
itstome
------------------------------------------------------------------------
itstome's Profile: http://www.excelforum.com/member.php...o&userid=26787
View this thread: http://www.excelforum.com/showthread...hreadid=400413





All times are GMT +1. The time now is 03:54 AM.

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