Closed Thread
Results 1 to 8 of 8

Apply VBA code to multiple cells

Hybrid View

  1. #1
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,646

    Re: Apply VBA code to multiple cells

    You're welcome.




    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  2. #2
    Registered User
    Join Date
    11-14-2024
    Location
    karachi, pakistan
    MS-Off Ver
    2016
    Posts
    3

    Re: Apply VBA code to multiple cells

    I want to apply the below VB code on the whole column "I " kindly guided please


    Private Sub Worksheet_Change(ByVal Target As Range)
    
    ' Initializing variables
    Dim oldVal As String
    Dim newVal As String
    
    ' Checking for changes in the drop down lists
    
    Application.EnableEvents = True
    
    If Target.Address = "$I$4" Or Target.Address = "$G$3" Then
        
        If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
            Exit Sub
    ' Adding the multiple selected items to the list
        Else
            If Target.Value = "" Then
                Exit Sub
    
            Else
                Application.EnableEvents = False
                newVal = Target.Value
                Application.Undo
                oldVal = Target.Value
                If oldVal = "" Then
                    Target.Value = newVal
                Else
                    If InStr(oldVal, newVal) = 0 Then
                        Target.Value = oldVal & ", " & newVal '& vbNewLine &
                    Else
                        Target.Value = oldVal
                    End If
                End If
            End If
        End If
    End If
    
    Application.EnableEvents = True
    
    End Sub
    Last edited by AliGW; 11-14-2024 at 08:07 AM. Reason: Code tags added - please review the forum guidelines.

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Apply VBA code to multiple sheets
    By PaulusKabouter in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-26-2013, 11:37 AM
  2. Apply VBA code to multiple cells
    By jond291 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-31-2013, 07:33 AM
  3. [SOLVED] Can i modify this code to apply to multiple checkboxes and sheets?
    By stolen_83 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-14-2013, 02:44 PM
  4. [SOLVED] Match code to apply multiple cells in 1 Sub
    By colvinb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-20-2012, 06:38 AM
  5. Need to apply VBA code to multiple Worksheets
    By parteegolfer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-12-2006, 04:43 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