Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Checking for cell content
I need to know if a cell is empty so my code can paste into it if so. If I
were just entering a formula into a worksheet I'd just use COUNT or COUNTA. But I'm not sure what the equivalent check in VBA is. Unfortunately, my data will at times include zeros so checking for 0 isn't working either. If anyone can help me, it's very much appreciated. Dan |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Checking for cell content
Sub routine()
If IsEmpty(Selection) Then MsgBox ("Really empty") End If End Sub -- Gary's Student "danhattan" wrote: I need to know if a cell is empty so my code can paste into it if so. If I were just entering a formula into a worksheet I'd just use COUNT or COUNTA. But I'm not sure what the equivalent check in VBA is. Unfortunately, my data will at times include zeros so checking for 0 isn't working either. If anyone can help me, it's very much appreciated. Dan |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Checking for cell content
For one cell:
if isempty(yourrangehere.value) then If it's multiple cells: if application.counta(yourrangehere) = 0 then danhattan wrote: I need to know if a cell is empty so my code can paste into it if so. If I were just entering a formula into a worksheet I'd just use COUNT or COUNTA. But I'm not sure what the equivalent check in VBA is. Unfortunately, my data will at times include zeros so checking for 0 isn't working either. If anyone can help me, it's very much appreciated. Dan -- Dave Peterson |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Checking for cell content
That worked perfectly. Thanks very much for the help.
"Gary''s Student" wrote: Sub routine() If IsEmpty(Selection) Then MsgBox ("Really empty") End If End Sub -- Gary's Student "danhattan" wrote: I need to know if a cell is empty so my code can paste into it if so. If I were just entering a formula into a worksheet I'd just use COUNT or COUNTA. But I'm not sure what the equivalent check in VBA is. Unfortunately, my data will at times include zeros so checking for 0 isn't working either. If anyone can help me, it's very much appreciated. Dan |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Checking for cell content
That worked very well, so I thank you for that, but wonder if you might be
able to clear up another bit of confusion. After I made the post, I wondered if activecell.value = true might be a good test. Whipped it up in a test spreadsheet and it worked. But when I put it into the real spreadsheet this morning, it didn't recognize 0's as cell content. Is there a simple explanation for why that would be? If you have the time to answer, again, much appreciated. "Dave Peterson" wrote: For one cell: if isempty(yourrangehere.value) then If it's multiple cells: if application.counta(yourrangehere) = 0 then danhattan wrote: I need to know if a cell is empty so my code can paste into it if so. If I were just entering a formula into a worksheet I'd just use COUNT or COUNTA. But I'm not sure what the equivalent check in VBA is. Unfortunately, my data will at times include zeros so checking for 0 isn't working either. If anyone can help me, it's very much appreciated. Dan -- Dave Peterson |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Checking for cell content
VBA sees True as -1.
and every other value as false. I'm not sure what was in your cell to get it to work, though. danhattan wrote: That worked very well, so I thank you for that, but wonder if you might be able to clear up another bit of confusion. After I made the post, I wondered if activecell.value = true might be a good test. Whipped it up in a test spreadsheet and it worked. But when I put it into the real spreadsheet this morning, it didn't recognize 0's as cell content. Is there a simple explanation for why that would be? If you have the time to answer, again, much appreciated. "Dave Peterson" wrote: For one cell: if isempty(yourrangehere.value) then If it's multiple cells: if application.counta(yourrangehere) = 0 then danhattan wrote: I need to know if a cell is empty so my code can paste into it if so. If I were just entering a formula into a worksheet I'd just use COUNT or COUNTA. But I'm not sure what the equivalent check in VBA is. Unfortunately, my data will at times include zeros so checking for 0 isn't working either. If anyone can help me, it's very much appreciated. Dan -- Dave Peterson -- Dave Peterson |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Checking for cell content
Well, my test code was just a simple If ActiveCell.Value = True, and if so,
msgbox Something In There, and if not msgbox Nothing There. When I put a number in the cell, I got the first msgbox, and when I deleted it, got the latter. Having never used that method before, deduced that it would recognize any cell that had content. However, when I then applied it to a true range of data, it considered cells with a zero in it to be empty and wrote over them rather than skipping past to the next truly empty cell. Thanks for the reply by the way. It helps to know that I wasn't using that piece of code correctly. "Dave Peterson" wrote: VBA sees True as -1. and every other value as false. I'm not sure what was in your cell to get it to work, though. danhattan wrote: That worked very well, so I thank you for that, but wonder if you might be able to clear up another bit of confusion. After I made the post, I wondered if activecell.value = true might be a good test. Whipped it up in a test spreadsheet and it worked. But when I put it into the real spreadsheet this morning, it didn't recognize 0's as cell content. Is there a simple explanation for why that would be? If you have the time to answer, again, much appreciated. "Dave Peterson" wrote: For one cell: if isempty(yourrangehere.value) then If it's multiple cells: if application.counta(yourrangehere) = 0 then danhattan wrote: I need to know if a cell is empty so my code can paste into it if so. If I were just entering a formula into a worksheet I'd just use COUNT or COUNTA. But I'm not sure what the equivalent check in VBA is. Unfortunately, my data will at times include zeros so checking for 0 isn't working either. If anyone can help me, it's very much appreciated. Dan -- Dave Peterson -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Spell Checking with checking cell notes | Excel Discussion (Misc queries) | |||
copy comment content to cell content as data not as comment | Excel Discussion (Misc queries) | |||
Checking range of cells for entry then checking for total | Excel Programming | |||
Checking and merging content from several worksheets | Excel Programming | |||
Checking for non-numerical content in a cell | Excel Programming |