PDA

View Full Version : Cell Value



JeffK
12-02-2015, 01:26 PM
so what would one do to put a specified value in the cell? I found that it can either be "" or 0 depending - my goal is to just have one of a certain thing in the cells such that I can write code like, if cells(row, col).value = "" then . . . What is tripping me up is that the inserted cells can contain 0 (not "0", just 0) and my code falls apart.

thanks,

JeffK

SamT
12-02-2015, 04:39 PM
so what would one do to put a specified value in the cell?Type carefully. :dunno


I found that it can either be "" or 0 dependingHow does that relate to the above?


What is tripping me up is that the inserted cells can contain 0 (not "0", just 0) and my code falls apart.What do you mean 0 (not "0", just 0) and what happened to ""

I am sorry, but you are not being very clear as to what you mean.

to test for an empty cell

If .Value = "" Then

To test for an o (Oh, not Zero)

If .Value = "O"Then
'or
If Lcase(.Value) = "o"Then
'LCase(.Value) = "o" tests for OH and oh

To Test if an O (Oh) is in the Cell (hellO")

If Instr(.Value, "O") > 0 Then '> Zero
'Or
If Instr(Lcase(.Value), "o") > 0 Then
To test if it is anything other than an Oh

If Not .Value = "O" Then
'Or
If .Value <> "O" Then

If you Type "Hello" including the Quote Marks, into a cell, then VBA sees the Quote Marks as part of the String

If .Value = ""hello"" then

JeffK
12-03-2015, 12:33 PM
Hello SamT,
What I want to do - select an area, insert cells and have the cells contain the same values for a blank. Right now, when I insert a block of cells, all are blank to the eye, but
when I do
val = Selection.Offset(y,x).value,
and look in my watchlist, I see literally, either val="<null>" or val = 0 - and I do mean 0, not "0".

I'm wondering if this is due to existing format rules in the spreadsheet that yield either "<null>" or 0. I only see 0 in one column, the rest are all "<null>". If so, I am curious as to what I can add to the insert command to give the cells the same format or, put the same value to an empty cell.

Thanks,
JeffK

SamT
12-03-2015, 12:53 PM
The values reported in the Watch window for empty Cells depends on the Cell formatting. If it's formatted as a number the value will be Zero.

Format one as a Date and one as Text and see what happens.

And please don't say "and I do mean 0, not "0"." Say Zero if you mean 0 instead of O, Say String("0")( Zero) if you mean the keyboard character that stands for Zero You don't know what Font anyone else is using and O & 0 may appear identical to their eye, and Oh, Not "Oh" is just confusing.

mikerickson
12-03-2015, 10:46 PM
If A1 is blank, then the formula =A1 (in some other cell) will return 0. This question sounds related to that.


... and my code falls apart.
What code is it that falls apart?
Could you attach a workbook that shows the problem and your desired result?