Clearing certain cells in a new Data Table row when Dropdown List selection changes

baseball17bucks

New Member
Joined
Oct 8, 2014
Messages
9
Hi there!

I am fairly new to VBA and brand new to mrexcel.com so please be as detailed as possible in responses (thanks!).

My issue: I have a data table called "DataEntry" It has four columns (i.e. fields) - JobType, Rate, Hours, and TotalPayment.
  • JobType is a dropdown list of choices (i.e. Clerk, Janitor, Accountant, etc.)
  • Rate is a vlookup to another table
  • Hours is a manual input for a user
  • TotalPayment is a calculation of Rate x Hours

My goal: If someone changes their choice of JobType, I want Hours to be cleared. Notice that I still wish to maintain the formulas for Rate and TotalPayment.

Any ideas or approaches? I've found the following code which seems to be on the right track, but I'm not sure how to scale it up to perform on a growing data table.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address(0, 0) = "B10" Then Range("E10").ClearContents
End Sub

Here, B10 is the "JobType" row in my table, and E10 is the first Hours row. When I change JobType, Hours is cleared, but I don't know how to get this to work for the rest of the table.

Thanks again for your detailed response!!! :)
 
Last edited:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
.
.

Place the following macro in the code module corresponding to that particular worksheet:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim Rang As Range
    Dim Cell As Range
    
    Set Rang = Intersect(Target, Me.Columns("B"))
    
    If Not Rang Is Nothing Then
        For Each Cell In Rang
            Application.EnableEvents = False
            Me.Cells(Cell.Row, "E").ClearContents
            Application.EnableEvents = True
        Next Cell
    End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,001
Messages
6,122,648
Members
449,092
Latest member
peppernaut

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