+ Reply to Thread
Results 1 to 4 of 4

how to make this vba code active row not cell

Hybrid View

  1. #1
    Forum Contributor sspreyer's Avatar
    Join Date
    07-05-2013
    Location
    london
    MS-Off Ver
    Excel 365 enterprise
    Posts
    191

    how to make this vba code active row not cell

    how can make this active row not active cell
    thanks in advance

     If Not Application.Intersect(ActiveCell, Range("a1:u500")) Is Nothing And ActiveCell.Value = 133 Or ActiveCell.Value = 122 Then
        MsgBox "        number not allowed! "
        Exit Sub
       End If

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: how to make this vba code active row not cell

    Could you provide a little context?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor sspreyer's Avatar
    Join Date
    07-05-2013
    Location
    london
    MS-Off Ver
    Excel 365 enterprise
    Posts
    191

    Re: how to make this vba code active row not cell

    hi

    basically im trying to a stop command button from working e.g if a13 to a500 has 133 enter in cell,the problem i have got is that if the cell is not first cell selected ie the active one the command button will work if i was to select cell from m13 to a13 the command button would work this why i think active row would work better but can seem to get it to work hope this helps. The macro is mail selection email button
    many thanks again
    shane
    Option Explicit
    
    Sub Mail_Selection_Outlook_Body()
    
       If Not Application.Intersect(ActiveCell, Range("A13:A500")) Is Nothing And ActiveCell.Value = 133 Or ActiveCell.Value = 122 Then
        MsgBox "        not allow number! "
        Exit Sub
       End If
        Dim rng As Range
        Dim OutApp As Object
        Dim OutMail As Object
     
        With Application
            .EnableEvents = False
            .ScreenUpdating = False
        End With
     
        Set rng = Nothing
        On Error Resume Next
        Set rng = Selection.SpecialCells(xlCellTypeVisible)
        On Error GoTo 0
     
        If rng Is Nothing Then
            MsgBox "The selection is not a range or the sheet is protected" & _
                   vbNewLine & "please correct and try again.", vbOKOnly
            Exit Sub
        End If
     
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
     
        On Error Resume Next
        With OutMail
            .To = ""
            .CC = ""
            .BCC = ""
            .Subject = "This is the Subject line"
            .HTMLBody = RangetoHTML(rng)
            .Display   'or use .Send
        End With
        On Error GoTo 0
     
        With Application
            .EnableEvents = True
            .ScreenUpdating = True
        End With
     
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub
    
    Sub Mail_Range_Outlook_Body()
    ' Don't forget to copy the function RangetoHTML in the module.
    ' Working in Office 2000-2010
        Dim rng As Range
        Dim OutApp As Object
        Dim OutMail As Object
     
        With Application
            .EnableEvents = False
            .ScreenUpdating = False
        End With
     
        Set rng = Nothing
        On Error Resume Next
        Set rng = Sheets("MailRangeSelection").Range("B19:B24").SpecialCells(xlCellTypeVisible)
        On Error GoTo 0
     
        If rng Is Nothing Then
            MsgBox "The selection is not a range or the sheet is protected" & _
                   vbNewLine & "please correct and try again.", vbOKOnly
            Exit Sub
        End If
     
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
     
        On Error Resume Next
        With OutMail
            .To = ""
            .CC = ""
            .BCC = ""
            .Subject = "This is the Subject line"
            .HTMLBody = RangetoHTML(rng)
            .Display   'or use .Send
        End With
        On Error GoTo 0
     
        With Application
            .EnableEvents = True
            .ScreenUpdating = True
        End With
     
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub

  4. #4
    Forum Contributor sspreyer's Avatar
    Join Date
    07-05-2013
    Location
    london
    MS-Off Ver
    Excel 365 enterprise
    Posts
    191

    Re: how to make this vba code active row not cell

    Quote Originally Posted by shg View Post
    Could you provide a little context?
    hi

    basically im trying to a stop command button from working e.g if a13 to a500 has 133 enter in cell,the problem i have got is that if the cell is not first cell selected ie the active one the command button will work if i was to select cell from m13 to a13 the command button would work this why i think active row would work better but can seem to get it to work hope this helps. The macro is mail selection email button
    many thanks again
    shane
    Option Explicit
    
    Sub Mail_Selection_Outlook_Body()
    
       If Not Application.Intersect(ActiveCell, Range("A13:A500")) Is Nothing And ActiveCell.Value = 133 Or ActiveCell.Value = 122 Then
        MsgBox "        not allow number! "
        Exit Sub
       End If
        Dim rng As Range
        Dim OutApp As Object
        Dim OutMail As Object
     
        With Application
            .EnableEvents = False
            .ScreenUpdating = False
        End With
     
        Set rng = Nothing
        On Error Resume Next
        Set rng = Selection.SpecialCells(xlCellTypeVisible)
        On Error GoTo 0
     
        If rng Is Nothing Then
            MsgBox "The selection is not a range or the sheet is protected" & _
                   vbNewLine & "please correct and try again.", vbOKOnly
            Exit Sub
        End If
     
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
     
        On Error Resume Next
        With OutMail
            .To = ""
            .CC = ""
            .BCC = ""
            .Subject = "This is the Subject line"
            .HTMLBody = RangetoHTML(rng)
            .Display   'or use .Send
        End With
        On Error GoTo 0
     
        With Application
            .EnableEvents = True
            .ScreenUpdating = True
        End With
     
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub
    
    Sub Mail_Range_Outlook_Body()
    ' Don't forget to copy the function RangetoHTML in the module.
    ' Working in Office 2000-2010
        Dim rng As Range
        Dim OutApp As Object
        Dim OutMail As Object
     
        With Application
            .EnableEvents = False
            .ScreenUpdating = False
        End With
     
        Set rng = Nothing
        On Error Resume Next
        Set rng = Sheets("MailRangeSelection").Range("B19:B24").SpecialCells(xlCellTypeVisible)
        On Error GoTo 0
     
        If rng Is Nothing Then
            MsgBox "The selection is not a range or the sheet is protected" & _
                   vbNewLine & "please correct and try again.", vbOKOnly
            Exit Sub
        End If
     
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
     
        On Error Resume Next
        With OutMail
            .To = ""
            .CC = ""
            .BCC = ""
            .Subject = "This is the Subject line"
            .HTMLBody = RangetoHTML(rng)
            .Display   'or use .Send
        End With
        On Error GoTo 0
     
        With Application
            .EnableEvents = True
            .ScreenUpdating = True
        End With
     
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Make Active Cell be at the Top of the Screen
    By Gos-C in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-15-2010, 12:47 PM
  2. [SOLVED] Make the next cell active
    By jpacynski@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-28-2006, 02:00 PM
  3. Code to make a sheet active
    By hshayh0rn in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-05-2006, 06:30 PM
  4. [SOLVED] find text in a cell and make cell 2 cells below that active
    By shark102 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-20-2005, 10:05 AM
  5. [SOLVED] How to make a particula cell ACTIVE using C#
    By Srini in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-12-2005, 01:05 PM

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