+ Reply to Thread
Results 1 to 7 of 7

How can I fix this macro to work properly?

  1. #1
    Registered User
    Join Date
    10-11-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    53

    How can I fix this macro to work properly?

    How can I fix this macro for it to work properly?

    Option Explicit

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim cell1 As Range
    Dim cell2 As Range

    For Each cell1 In Sheets("FABRICATION WORK ORDER").Range("C1:C6,C9:C16,E28")
    If cell1.Value = "" Then
    Cancel = True
    MsgBox "Cell " & cell1.Address & " is empty - Please fill the cell before saving!", vbOKOnly, "Check Cells"
    Exit Sub
    End If
    Next cell1
    For Each cell2 In Sheets("INSTALLATION WORK ORDER").Range("D9:D15,D19:D22,I12:I19")
    If cell2.Value = "" Then
    Cancel = True
    MsgBox "Cell " & cell2.Address & " is empty - Please fill the cell before saving!", vbOKOnly, "Check Cells"
    Exit Sub
    End If


    Next cell2

    End Sub


    Private Sub Workbook_Open()

    End Sub
    I would like the error to look like "Cell C1 is empty - Please fill the cell before saving!" instead of the way it's show in the image below.

    Warning Message.jpg


    Thank you so much!
    Last edited by denisirio; 10-19-2012 at 12:12 PM.

  2. #2
    Registered User
    Join Date
    08-15-2012
    Location
    Las Vegas
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: How can I fix this macro to work properly?

    Please wrap your code in code tags.

    You can use the following code to get what you are looking for:

    Please Login or Register  to view this content.
    Last edited by g8r777; 10-18-2012 at 05:03 PM.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: How can I fix this macro to work properly?

    Please Login or Register  to view this content.

    Regrds, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    10-11-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: How can I fix this macro to work properly?

    I tried that and it didn't work. What exactly do I have to replace with what? I'm very new to the VB.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: How can I fix this macro to work properly?

    I tried that and it didn't work.
    Tried what and it didn't work?

    Please Login or Register  to view this content.

    Regards, TMS

  6. #6
    Registered User
    Join Date
    10-11-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: How can I fix this macro to work properly?

    Great! Thank you so much!!

    You guys at excel forum are the best!

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: How can I fix this macro to work properly?

    You're welcome.


    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ 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.6.0 RC 1