+ Reply to Thread
Results 1 to 5 of 5

Combining VB Codes

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-04-2013
    Location
    Arkansas
    MS-Off Ver
    Microsoft Excel 2016
    Posts
    252

    Combining VB Codes

    I am using the following code to capitalize the first letter of each word in columns D,E,F and I.

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.CountLarge > 1 Then Exit Sub
        If Not Intersect(Target, Range("D:D,E:E,F:F,I:I")) Is Nothing Then
            Application.EnableEvents = False
            Target.Value2 = Application.WorksheetFunction.Proper(Target)
            Application.EnableEvents = True
        End If
    End Sub
    What can I add to also Capitalize the entire word in columns C and J.

    Thank you

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,741

    Re: Combining VB Codes

    How about
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.CountLarge > 1 Then Exit Sub
        If Not Intersect(Target, Range("D:D,E:E,F:F,I:I")) Is Nothing Then
            Application.EnableEvents = False
            Target.Value2 = Application.WorksheetFunction.Proper(Target)
            Application.EnableEvents = True
        ElseIf Not Intersect(Target, Range("C:C,J:J")) Is Nothing Then
             Application.EnableEvents = False
            Target.Value = UCase(Target.Value)
            Application.EnableEvents = True
        End If
    End Sub

  3. #3
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,751

    Re: Combining VB Codes

    Try
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.CountLarge > 1 Then Exit Sub
        If Not Intersect(Target, Range("D:D,E:E,F:F,I:I")) Is Nothing Then
            Application.EnableEvents = False
            Target.Value2 = Application.WorksheetFunction.Proper(Target)
        Else
            If Not Intersect(Target, Range("C:C,J:J")) Is Nothing Then
                Application.EnableEvents = False
                Target.Value2 = UCase(Target)
            End If
        End If
        Application.EnableEvents = True
    End Sub
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  4. #4
    Forum Contributor
    Join Date
    01-04-2013
    Location
    Arkansas
    MS-Off Ver
    Microsoft Excel 2016
    Posts
    252

    Re: Combining VB Codes

    Fluff13 and JohnTopley,

    "Else", got it. Thank you both.

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,741

    Re: Combining VB Codes

    Glad to help & thanks for the feedback.

+ 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. [SOLVED] Combining VBA Codes
    By BradleyCase in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-05-2019, 07:04 PM
  2. Combining two codes
    By kbenjamin827 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-11-2019, 11:33 AM
  3. Need help combining two codes
    By kbenjamin827 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 01-09-2019, 05:03 PM
  4. Combining two codes into one
    By Aqmas in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-08-2017, 03:46 PM
  5. Combining vba codes makes the previous codes broken !
    By MDPLUS in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-26-2013, 10:00 AM
  6. [SOLVED] Help! combining 2 VBA codes
    By iamreese in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-29-2012, 07:24 AM
  7. [SOLVED] combining 2 codes
    By steve in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-18-2006, 01:15 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