+ Reply to Thread
Results 1 to 3 of 3

Can you exclude coloums from a macro that runs automatically?

Hybrid View

  1. #1
    Registered User
    Join Date
    12-30-2010
    Location
    Huddersfield, England
    MS-Off Ver
    Excel 2010
    Posts
    58

    Can you exclude coloums from a macro that runs automatically?

    I have a code that when the user clicks off the cell it automatically sets it to 'PROPER'.

    Can i set it to exclude coloums suchs as D & N?

    Private Sub Worksheet_Change(ByVal Target As Range)
       Dim rngSrc As Range
       On Error GoTo err_handler
       Application.EnableEvents = False
       For Each rngSrc In Target.Cells
          With rngSrc
             If Not .HasFormula Then .Value = StrConv(.Value, vbProperCase)
          End With
       Next rngSrc
    
    clean_up:
       Application.EnableEvents = True
       Exit Sub
    
    err_handler:
       MsgBox Err.Description
       Resume clean_up
    End Sub
    Last edited by snoopy1461; 03-31-2011 at 09:37 AM. Reason: Solved

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Can you exclude coloums from a macro that runs automatically?

    hi, snoopy1461, try this out:

    Private Sub Worksheet_Change(ByVal Target As Range)
       Dim rngSrc As Range
       On Error GoTo err_handler
       Application.EnableEvents = False
       For Each rngSrc In Target.Cells
          With rngSrc
             If rngSrc.Column <> 4 And rngSrc.Column <> 14 Then
                If Not .HasFormula Then .Value = StrConv(.Value, vbProperCase)
             End If
          End With
       Next rngSrc
    
    clean_up:
       Application.EnableEvents = True
       Exit Sub
    
    err_handler:
       MsgBox Err.Description
       Resume clean_up
    End Sub

  3. #3
    Registered User
    Join Date
    12-30-2010
    Location
    Huddersfield, England
    MS-Off Ver
    Excel 2010
    Posts
    58

    Re: Can you exclude coloums from a macro that runs automatically?

    Thanks alot, its worked perfectly!!!

+ 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