+ Reply to Thread
Results 1 to 3 of 3

Thread: Correct way to write VBA Macros

  1. #1
    Valued Forum Contributor
    Join Date
    01-11-2012
    Location
    riyadh
    MS-Off Ver
    Excel 2003
    Posts
    413

    Smile Correct way to write VBA Macros

    Hello,

    Can anyone correct this below mentioned script. I want to display a message if the range have empty cells or make cell empty and display the message.

    'If Sheets("Template").Range("A2:J65536") = " " Then
       'Msg = "Records Already Empty."  
       'Style = vbOKOnly + vbInformation '+ vbDefaultButton2
       'Title = "Underwriting Department"
       'Response = MsgBox(Msg, Style, Title, Help, Ctxt)
       'End If
        
       'If Sheets("Template").Range("A2:J65536") <> "" Then
       'Sheets("Template").Range("A2:J65536").ClearContents
       'Msg = "Records Clear." 
       'Style = vbOKOnly + vbInformation '+ vbDefaultButton2
       'Title = "Underwriting Department"
       'Response = MsgBox(Msg, Style, Title, Help, Ctxt)
       'End If
    Thanks in advance for your help.
    Last edited by hecgroups; 02-13-2012 at 11:05 AM.

  2. #2
    Forum Guru Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    MS Excel 2010
    Posts
    2,251

    Re: Correct way to write VBA Macros

        With Worksheets("Template")
        
            If Application.CountA(.Range("A2:J65536")) = 0 Then
            
                Response = MsgBox("Records Already Empty.", vbOKOnly + vbInformation, "Underwriting Department")
            Else
           
                .Range("A2:J65536").ClearContents
                Response = MsgBox("Records Clear.", vbOKOnly + vbInformation, "Underwriting Department")
            End If
        End With

  3. #3
    Valued Forum Contributor
    Join Date
    01-11-2012
    Location
    riyadh
    MS-Off Ver
    Excel 2003
    Posts
    413

    Re: Correct way to write VBA Macros

    Thanks bob it works perfectly with my original file. Excellent script.

+ 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