ladymrt
ladymrt

Reputation: 95

If Statement with an InputBox - Not Working

I am trying to write a macro that looks at a cell and tells me if it's empty, and if it is, open up an input box to fill in the cell. The below code is not opening the message box regardless if the cell is empty or not. C37 IS A MERGED CELL which I know could be mucking things up. What am I missing here?

If IsEmpty("C37") Then


Dim SIGN As String          'Sign-off

SIGN = InputBox("Enter Your Name:", "Dispositioned By:")

Range("C37").Value = SIGN
Range("G37").Value = Format(Now(), "MM/DD/YYYY")

Else

Range("B26").Select

End If

UPDATE:

With ActiveSheet

 If IsEmpty(ActiveWorkbook.ActiveSheet.Range("C23")) Then

 Dim SIGN As String          'Sign-off

 SIGN = InputBox("Enter Your Name:", "Dispositioned By:")

 Range("C23").Value = SIGN
 Range("G23").Value = Format(Now(), "MM/DD/YYYY")

 Else

 Range("B13").Select

 End If
 End With

Is the new code I've ended up with. This is not opening the inputbox even when the cell is "empty"

Is there a different phrase I should be using than IsEmpty?

Upvotes: 2

Views: 1142

Answers (3)

ladymrt
ladymrt

Reputation: 95

Okay. I've solved my problem.

I have a button that resets this form to clear contents of the cells and start over.

Unfortunately, I couldn't find a way to easily clear contents of a merged cell, so instead, I used

Range("MERGEDCELL").Value = " "

to essentially make the cell blank. HOWEVER, my IsEmpty is not going to see those cells as empty because they have a space in them, thus why when it looks empty to me (but it's not) the InputBox doesn't pop up...

I've looked around for alternatives to clear contents of merged cell with little to no success. If anyone has suggestions in that area, let me know. Thanks again for everything everyone.

Upvotes: 0

Rajesh Sinha
Rajesh Sinha

Reputation: 197

If IsEmpty(Range( "C37" )) = True Then

SIGN = InputBox( "Enter Your Name:")

Range( "C37" ).Value = SIGN

Else

Your code

Upvotes: -1

Doug Coats
Doug Coats

Reputation: 7107

 If IsEmpty(ThisWorkbook.Worksheets("Sheet1").Range("C37"))

The issue is you did not tell the IsEmpty function to check for a range. You told it to check for "C37" which is a string literal and not a range object.

Upvotes: 3

Related Questions