Setting & getting blank value to/from a cell ?

jxb

Board Regular
Joined
Apr 19, 2007
Messages
172
Office Version
  1. 2010
Platform
  1. Windows
To all

I have a xls sheet which contains formulas as follows
In cell C1
= If($A$1<> “”, 99,””)

The idea is that a value is written if A1 contains something (i.e. a value) otherwise no value is written. I do not want 0. I want a blank cell

Then in a macro I pick up the value from cell C1 as follows

Dim ValueToUse As Double
ValueToUse = CDbl(CurrentSh.Cells(1, 3).Value)

If Not (IsEmpty(ValueToUse) Then
‘do something
End if

I am having trouble with the “empty” cell, as I get Type Mismatch. Hence my trying to force the value to a Double using CDbl()

Q: Is there a “smart” way of writing nothing in a cell?

The examples are simplified code

Thanks
Regards
JXB
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Try
Code:
If Not Range("C1").Value="" Then
 
Upvote 0
Thanks Fluff

Totally "bypassing" a variable definition seem to work. Will carry on checking but 1st pass seem to work

I originally defined specific variable names to make the code easier to read (instead of having things like

If Not (CurrentSh.Cells(ThisRow, Rtcol).Value = "" And _
CurrentSh.Cells(ThisRow, RsCol).Value = "") Then
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top