ActiveCell giving blank value in vbscript

I

itstome

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 advanc
 
B

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top