I'm building an Excel file that imports data from another Excel file and populates a table. I have this functionality working but I'm now trying to have cells update based on entries being changed in another column. Specifically, it needs to do 3 things:
I got it to work for a minute but then started getting type errors or just not working at all. The following script is what I have developed.
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, ActiveSheet.ListObjects("GraphicTable").ListColumns(12).DataBodyRange) Is Nothing Then
If Target.Value = "Remove" Then
Target.Offset(0, -2).Value = "No"
End If
End If
If Not Intersect(Target, ActiveSheet.ListObjects("GraphicTable").ListColumns(10).DataBodyRange) Is Nothing Then
If Target.Value = "No" Then
Target.Offset(0, 1).Value = 0
Else
Target.Offset(0, 2).Value = ""
Call HoursCalc
End If
End If
End Sub
Several things that may help, as I haven't seen update to include which errors are being received:
select
when I'm combining my change events, rather than separate if
statements so a single-pass check occurs (could similarly use else-if
);activesheet
instead of me
because it is tied to a sheet could lead to issues;target.count
as that can oftentimes lead to issues;application.run
which will run the subroutine even if it is private
;Untested:
if target.count > 1 then exit sub
with target
select case true
case not intersect(target, Me.ListObjects("GraphicTable").ListColumns(10).DataBodyRange) is nothing
if .value = "Remove" then .offset(,-2).value = "No"
case not intersect(target, Me.ListObjects("GraphicTable").ListColumns(10).DataBodyRange) is nothing
if .value = "No" then
.offset(,1).value = 0
else
.offset(,2).clearcontents
application.run "module1.HoursCalc"
end if
end select
end with
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.