Referencing a Cell with Select Case or If

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,113
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I'm trying to reference a cell in vba of
Code:
Sheet1.B5
that has the formula
Code:
=IF(Sheet2!B6=0,"",Sheet2!B6)
present there.

In using the Select Case &/or If statements, I cannot seem to create the correct criteria whereby the referenced cell of
Code:
Sheet1.B5
is truly blank.

If I use:

Code:
Sub TestBlank()
If Not Sheet1.Range("B5").Value= "" Then
'If Cell is Occupied Then
    'or Text

    MsgBox "Occupied"
    
    
End If

If Sheet1.Range("B5").Value = "" Then
'If Cell is Blank Then
    'or Text

    MsgBox "Blank"
    '
End If
End Sub

Or

Code:
Select Case True
Case Not Sheet1.Range("B5").Value = ""
'If Cell is Occupied Then
    'or Text

    MsgBox "Occupied"
    
    
    
Case Sheet1.Range("B5").Value = ""
'If Cell is Blank Then
    'or Text

    MsgBox "Blank"
    '
    
End Select


This is confusing me.

Can you please lend me your thoughts?

Many thanks,
pinaceous
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi All,

I'm trying to reference a cell in vba of
Code:
Sheet1.B5
that has the formula
Code:
=IF(Sheet2!B6=0,"",Sheet2!B6)
present there.

In using the Select Case &/or If statements, I cannot seem to create the correct criteria whereby the referenced cell of Sheet1.B5 is truly blank.

If I use:

Code:
Sub TestBlank()
If Not Sheet1.Range("B5").Value= "" Then
'If Cell is Occupied Then
    'or Text

    MsgBox "Occupied"
    
    
End If

If Sheet1.Range("B5").Value = "" Then
'If Cell is Blank Then
    'or Text

    MsgBox "Blank"
    '
End If
End Sub

Or

Code:
Select Case True
Case Not Sheet1.Range("B5").Value = ""
'If Cell is Occupied Then
    'or Text

    MsgBox "Occupied"
    
    
    
Case Sheet1.Range("B5").Value = ""
'If Cell is Blank Then
    'or Text

    MsgBox "Blank"
    '
    
End Select


This is confusing me.

Can you please lend me your thoughts?

Many thanks,
pinaceous
Your question is unclear to me. If the cell you want to reference has a formula in it, it cannot be "truly blank". Can you elaborate on what you want to do?
 
Upvote 0
Your question is unclear to me. If the cell you want to reference has a formula in it, it cannot be "truly blank". Can you elaborate on what you want to do?

That is actually my question. If the cell you want to reference has a formula, it cannot be blank?

If that is the case, I'll be looking at a copy paste onto a sheet to try and work around that fact. I was hoping that this cell with a formula could be hidden to appear blank to the code.

Thanks,
Paul
 
Upvote 0
Try
Code:
If IsEmpty(Sheet1.Range("B5").Value) Then
  MsgBox "Unoccupied"
Else
  MsgBox "Occupied"
End If
 
Upvote 0
Try
Code:
If IsEmpty(Sheet1.Range("B5").Value) Then
  MsgBox "Unoccupied"
Else
  MsgBox "Occupied"
End If

Hi Peter_SSs,

For the cell of
Code:
Sheet1.Range("B5").Value
I have this cell first being populated by
Code:
 xlPasteValues
from a table.

Now the problem is that after the
Code:
 xlPasteValues
is executed, the
Code:
 If IsEmpty
function does not work because it thinks that something is there a value.

Do you know how I can work around this issue?

Many thanks,
Paul
 
Last edited:
Upvote 0
What do you really have in Sheet1.Range("B5")
- In posts 1 and 3 you said it had a formula
- Now you are saying it has a pasted value

Which is it?
 
Upvote 0
Hi Peter,

I messed up where I realized that my copy paste from my table was carrying over values that were hidden.

Your codes are perfect.

Sorry for the ambiguity.

Thanks,
Paul
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,796
Members
449,095
Latest member
m_smith_solihull

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