Cell Change in Table

JeannetteE

Board Regular
Joined
May 19, 2016
Messages
53
Hi,

The following code does exactly what I need it to do when the relevant Cells change, however I need it to represent a Table. Table Name and Table Headers are commented in the Code. Any help greatly appreciated.


Code:
Private Sub Worksheet_Change(ByVal Target As Range)


' Table Name = tblSMSubCategories
' Column G Table Header = Sub-Category
' Column I Table Header = Incident Type
' Column M Table Header = Specifics Type
' Column P Table Header = Ticket Creation Action to Run




    If Target.Address = "G10" Then
        If Range("I10").Value = "Service Request" And Range("M10").Value = "" Then
            Range("M10").Value = "Select from List"
        Else
        If Range("I10").Value = "Incident" Then
        Range("M10").Value = ""
        End If
        End If
    End If


    If Target.Address = "M10" Then
        If Range("M10").Value = "Specifics - Product Catalogue" And Range("P10").Value = "" Then
            Range("P10").Value = "Select from List"
        Else
        Range("P10").Value = ""
        End If
    End If


End Sub
 
Last edited:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)


    Dim sh As Worksheet, lo As ListObject, ini As Long, n As Long
    
    Set sh = ActiveSheet
    Set lo = sh.ListObjects("tblSMSubCategories")
    ini = lo.Range.Row


    ' Table Name = tblSMSubCategories
    ' Column G Table Header = Sub-Category
    ' Column I Table Header = Incident Type
    ' Column M Table Header = Specifics Type
    ' Column P Table Header = Ticket Creation Action to Run


    If Target.Count > 1 Then Exit Sub
    n = Target.Row - ini
    If Not Intersect(Target, Range("tblSMSubCategories[Sub-Category]")) Is Nothing Then
        If lo.DataBodyRange(n, lo.ListColumns("Incident Type").Index).Value = "Service Request" And _
           lo.DataBodyRange(n, lo.ListColumns("Specifics Type").Index).Value = "" Then
            lo.DataBodyRange(n, lo.ListColumns("Specifics Type").Index).Value = "Select from List"
        Else
            lo.DataBodyRange(n, lo.ListColumns("Specifics Type").Index).Value = ""
        End If
    End If


    If Not Intersect(Target, Range("tblSMSubCategories[Specifics Type]")) Is Nothing Then
        If lo.DataBodyRange(n, lo.ListColumns("Specifics Type").Index).Value = "Specifics - Product Catalogue" And _
           lo.DataBodyRange(n, lo.ListColumns("Ticket Creation Action to Run").Index).Value = "" Then
            lo.DataBodyRange(n, lo.ListColumns("Ticket Creation Action to Run").Index).Value = "Select from List"
        Else
            lo.DataBodyRange(n, lo.ListColumns("Ticket Creation Action to Run").Index).Value = ""
        End If
    End If
End Sub
 
Upvote 0
Solution
This is off-topic, but did you notice your columns spell out GIMP? Made me think of my photo editing app.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top