Advice for if cell has a value then

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
The code in use is shown below.
Im in need of some help please for when the code checks the active cell.

I have in place the code shown in Red below if it has no value / empty etc

But can you advise what i need to put should it have a value etc & where i need to put it.

I did try this but it wasnt happening at the correct point.

Rich (BB code):
If ActiveCell.Value <> 0 Then

MsgBox "CELL ISNT EMPTY"

End If

Rich (BB code):
Private Sub TEST_Click()
    Dim answer As Integer
    Dim rng As Range
    Dim cell As Range
    Dim findString As String
    Dim sPath As String, strFileName As String
    Dim srcWS As Worksheet, destWS As Worksheet
    Set srcWS = ActiveWorkbook.Worksheets("INV")
    Set destWS = ActiveWorkbook.Worksheets("DATABASE")
    
      
      strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DR\DR COPY INVOICES\" & Range("L4").Value & ".pdf"
    If Range("L18") = "" Then
      MsgBox ("PLEASE SELECT A PAYMENT TYPE "), vbCritical, "PAYMENT TYPE WAS NOT SELECTED"
      Range("L18").Select
    Exit Sub
    End If
  
    strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DR\DR COPY INVOICES\" & Range("L4").Value & ".pdf"
    If Dir(strFileName) <> vbNullString Then
    MsgBox "INVOICE " & Range("L4").Value & " WAS NOT SAVED AS IT ALLREADY EXISTS" & vbNewLine & vbNewLine & "PLEASE CHECK FILE IN FOLDER THAT WILL NOW OPEN.", vbCritical + vbOKOnly, "INVOICE NOT SAVED MESSAGE"
    
    VBA.Shell "explorer.exe /select, " & "" & strFileName & "", vbNormalFocus
    Exit Sub
  
    End If
    With ActiveSheet
    .ExportAsFixedFormat Type:=xlTypePDF, fileName:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
    End With
    With Sheets("DATABASE")
      Worksheets("DATABASE").Activate
    End With

    Set rng = ActiveSheet.Columns("A:A")

    findString = Worksheets("INV").Range("G13").Value

    Set cell = rng.Find(What:=findString, LookIn:=xlFormulas, _
    LookAt:=xlWhole, MatchCase:=False)

    If cell Is Nothing Then
    MsgBox "NO CUSTOMER WAS FOUND"
    Else
    With Sheets("DATABASE")
    cell.Select
    ActiveCell.Offset(0, 15).Select
    End With
    
    If ActiveCell.Value = "" Then
    TransferInvoiceNumber.Show
    End If
    End If
 
    With Sheets("DATABASE")
      Worksheets("INV").Activate
    With ActiveSheet
      ' ActiveWindow.SelectedSheets.PrintOut copies:=1
    MsgBox "NO PRINTING 1ST MSG"
       answer = MsgBox("INVOICE HAS NOW BEEN SAVED" & vbNewLine & vbNewLine & "DID THE INVOICE PRINT OK FOR YOU ?", vbInformation + vbYesNo, "INVOICE PRINT OK MESSAGE")
    If answer = vbNo Then
      ' ActiveWindow.SelectedSheets.PrintOut copies:=1
    MsgBox "NO PRINTING 2ND MSG"
    Exit Sub
    Else
     Range("L4").Value = Range("L4").Value + 1
     Range("G27:L36").ClearContents
     Range("G46:G50").ClearContents
     Range("L18").ClearContents
     Range("G13").ClearContents
     Range("G13").Select
     ActiveWorkbook.Save
    End If
    End With
    End With
    
End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Modify your original red code with the blue code:
Rich (BB code):
    If ActiveCell.Value = "" Then
       TransferInvoiceNumber.Show
    Else
       MsgBox "CELL ISN'T EMPTY"
    End If
I also added the apostrophe.
 
Upvote 0
Instead of
VBA Code:
If ActiveCell.Value = "" Then
use
VBA Code:
If Len(ActiveCell.Value) > 0 Then
Artik
 
Upvote 0
So hopefully applied correctly but dont see the Msgbox & code just continues even when the cell has a value in it

Rich (BB code):
    If cell Is Nothing Then
    MsgBox "NO CUSTOMER WAS FOUND"
    Else
    With Sheets("DATABASE")
    cell.Select
    ActiveCell.Offset(0, 15).Select
    End With
    
    If Len(ActiveCell.Value) > 0 Then
    TransferInvoiceNumber.Show
    Else
    MsgBox "CELL ISN'T EMPTY"
    End If
    End If
 
Upvote 0
I even tried this but still the same


Rich (BB code):
    If cell Is Nothing Then
    MsgBox "NO CUSTOMER WAS FOUND"
    Else
    With Sheets("DATABASE")
    cell.Select
    ActiveCell.Offset(0, 15).Select
    End With
    
    If Len(ActiveCell.Value) > 0 Then
       TransferInvoiceNumber.Show
    Else
    If Len(ActiveCell.Value) <> 0 Then
       MsgBox "CELL ISN'T EMPTY"
       Exit Sub
    End If
    End If
 
Upvote 0
Instead of
VBA Code:
If ActiveCell.Value = "" Then
use
VBA Code:
If Len(ActiveCell.Value) > 0 Then
Artik
These are logical opposites. it should be

Rich (BB code):
If Len(ActiveCell.Value) = 0 Then
 
Upvote 0
Isn’t that the same as what I mentioned in my code above

Code:
If Len(ActiveCell.Value) > 0 Then
 
Upvote 0

Forum statistics

Threads
1,215,071
Messages
6,122,963
Members
449,094
Latest member
Anshu121

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