Results 1 to 7 of 7

Select case using a range

Threaded View

  1. #1
    Registered User
    Join Date
    04-19-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    50

    Select case using a range

    Hi,

    I'm creating a small spreadsheet for client data in Excel and I want it formatted a certain way, I did consider data validation but it proved to just be annoying.

    I've been working on some VBA code to automatically change whatever text is typed into a cell to the correct case (ucase, lcase or proper) and while I can get it working for a single range of cells getting it to work for more is proving difficult.

    This is what I have so far;
    Private Sub Worksheet_change(ByVal Target As Range)
        If Target.Cells.Count > 1 Then
            Exit Sub
        End If
        On Error GoTo ErrHandler:
        
        Select Case Target
        
        Case Range("C2:C65535")
        
        If Not Application.Intersect(Me.Range("C2:C65535"), Target) Is Nothing Then
            If IsNumeric(Target.Value) = False Then
                Application.EnableEvents = False
                'Target.Value = StrConv(Target.Text, vbLowerCase)
                Target.Value = StrConv(Target.Text, vbUpperCase)
                'Target.Value = StrConv(Target.Text, vbProperCase)
                Application.EnableEvents = True
            End If
        End If
        
        Case Range("D2:D65535")
        
        If Not Application.Intersect(Me.Range("D2:D65535"), Target) Is Nothing Then
            If IsNumeric(Target.Value) = False Then
                Application.EnableEvents = False
                'Target.Value = StrConv(Target.Text, vbLowerCase)
                Target.Value = StrConv(Target.Text, vbUpperCase)
                'Target.Value = StrConv(Target.Text, vbProperCase)
                Application.EnableEvents = True
            End If
        End If
        
        Case Range("B2:B65535")
        
        If Not Application.Intersect(Me.Range("D2:D65535"), Target) Is Nothing Then
            If IsNumeric(Target.Value) = False Then
                Application.EnableEvents = False
                'Target.Value = StrConv(Target.Text, vbLowerCase)
                'Target.Value = StrConv(Target.Text, vbUpperCase)
                Target.Value = StrConv(Target.Text, vbProperCase)
                Application.EnableEvents = True
            End If
        End If
        
        End Select
    ErrHandler:
        Application.EnableEvents = True
        
        
    End Sub
    Last edited by royUK; 07-31-2009 at 06:13 AM.

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