Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Retrieving a value from a cell

I am writing a program with VB .NET that uses the Excel
object library. I tried to get a value from a cell and
assign it to a variable:

strVar = CStr(Worksheet.Range("A10").Value)

But if the cell is empty, the returned value is Nothing.
So I modified the code to check for Nothing:

With Worksheet
strVar = CStr(IIf(.Range("A10").Value =
Nothing, "", .Range("A10").Value))
End With

However, I kept getting an Error 91.

I tried checking the .Text property of the cell, but that
always comes back with an empty string if the cell is
hidden.

Any suggestion on how I accomplish this?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Retrieving a value from a cell

Hi Paul,

strVar = CStr(Worksheet.Range("A10").Value)


I had no problem with this.

However, the line:

With Worksheet


would might well cause a problem.

Try, instead:

With ActiveSheet

or With Worksheets("YourSheetName")


---
Regards,
Norman



"Paul Lee" wrote in message
...
I am writing a program with VB .NET that uses the Excel
object library. I tried to get a value from a cell and
assign it to a variable:

strVar = CStr(Worksheet.Range("A10").Value)

But if the cell is empty, the returned value is Nothing.
So I modified the code to check for Nothing:

With Worksheet
strVar = CStr(IIf(.Range("A10").Value =
Nothing, "", .Range("A10").Value))
End With

However, I kept getting an Error 91.

I tried checking the .Text property of the cell, but that
always comes back with an empty string if the cell is
hidden.

Any suggestion on how I accomplish this?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Retrieving a value from a cell

Paul,

Nothing isn't a value, it is a state

Try this (not tried on .Net)

With Worksheet
strVar = CStr(IIf(.Range("A10") Is Nothing, "", .Range("A10").Value))
End With

You might need

With Worksheet
strVar = CStr(IIf(.Range("A10").Value Is Nothing, "",
..Range("A10").Value))
End With

or even

With Worksheet
If .Range("A10") Is Nothing Then
strVar = ""
Else
strVar = CStr(IIf.Range("A10").Value)
End With


--

HTH

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

"Paul Lee" wrote in message
...
I am writing a program with VB .NET that uses the Excel
object library. I tried to get a value from a cell and
assign it to a variable:

strVar = CStr(Worksheet.Range("A10").Value)

But if the cell is empty, the returned value is Nothing.
So I modified the code to check for Nothing:

With Worksheet
strVar = CStr(IIf(.Range("A10").Value =
Nothing, "", .Range("A10").Value))
End With

However, I kept getting an Error 91.

I tried checking the .Text property of the cell, but that
always comes back with an empty string if the cell is
hidden.

Any suggestion on how I accomplish this?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieving hyperlink from cell dezy Excel Worksheet Functions 0 January 3rd 08 03:52 PM
Retrieving a tuple for a cell. SRK Excel Discussion (Misc queries) 0 November 6th 06 09:51 AM
Cell searching and retrieving fluci Excel Discussion (Misc queries) 5 August 4th 05 03:37 PM
Help Retrieving Cell Values Marshall Excel Programming 1 October 28th 03 05:32 PM
Retrieving a cell value with a SQL statement Douglas José Soares Rodrigues Excel Programming 0 August 12th 03 03:21 PM


All times are GMT +1. The time now is 01:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"