+ Reply to Thread
Results 1 to 3 of 3

Thread: If cell empty dont run macro

  1. #1
    Forum Contributor
    Join Date
    10-24-2008
    Location
    England
    Posts
    146

    If cell empty dont run macro

    How can this be edited so that if cell B5 is empty a msgbox comes up if not the macro follows through?

    Private Sub Worksheet_Change(ByVal Target As Range)
    Sheets("Headed Paper").Range("N1").Value = Sheets(ActiveSheet.Name).Range("A2").Value
    Sheets("Headed Paper").Range("O1").Value = Sheets(ActiveSheet.Name).Range("A3").Value
    
    Dim shSource As Worksheet, shDestination As Worksheet, iR As Long, i As Byte
    Set shSource = ActiveSheet
    Set shDestination = Sheets("Invoice Template") ' =Sheet4
    
    If Target.Count > 1 Then Exit Sub
    If (Not Intersect(Target, shSource.Range("J5:J500")) Is Nothing) And Target.Cells.Count = 1 Then
    If UCase(Target.Value) = "Y" Then
    Worksheets("Invoice Template").Visible = True
    Dim aso(), aco()
    aso = Array("A", "B", "C", "D", "G", "F", "H", "I")
    aco = Array("B14", "B16", "F16", "D35", "D36", "D37", "D38", "D39")
    
    iR = Target.Row
    For i = 0 To UBound(aso)
    Range("J" & iR).FormulaR1C1 = "DONE"
    shDestination.Range(aco(i)).Value = shSource.Range(aso(i) & iR).Value
    Next
    With Sheets("Invoice Template")
    .Range("N1").Value = Sheets(ActiveSheet.Name).Range("A2").Value
    .Range("O1").Value = Sheets(ActiveSheet.Name).Range("A3").Value
    
    End With
    Range("o3").Value = ("J" & iR)
    shDestination.Protect
    shDestination.Select
    Sheet1.Visible = False
    Sheet2.Visible = False
    Sheet5.Visible = False
    End If
    End If
    Application.EnableEvents = True
    End Sub
    Many Thanks

  2. #2
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,157

    Re: If cell empty dont run macro

    Start of like this...
    Private Sub Worksheet_Change(ByVal Target As Range)
    If IsEmpty(Range("B5")) Then
        MsgBox "Cell B5 is not supposed to be empty..."
        Exit Sub
    End If
    
    ....continue your macro
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  3. #3
    Valued Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: If cell empty dont run macro

    As the first line(s):

    If Range("B5").Value = "" Then
        MsgBox "B5 is blank"
        Exit Sub
    End If
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0