![](/img/trans.png)
[英]Is there a way in excel to apply a formula based conditional format for an entire column?
[英]Apply divide formula to entire column in macro on Excel?
我不仅要将此公式应用于B2单元格,而且要应用于整个B列。
Private Sub Worksheet_Change(ByVal Target As Range)
If Target = [B2] Then
Dim amount As Long
amount = [B2]
Application.EnableEvents = False
Target.Value = amount / (100000000)
Application.EnableEvents = True
End If
End Sub
任何帮助将不胜感激。
像这样:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range, c As Range, rngCol As Range
'Get the range from the table column header
Set rngCol = Me.ListObjects("myTable").ListColumns("Col2").DataBodyRange
'EDIT: alternative for multiple contiguous columns
Set rngCol = Me.Range("myTable[Col2]:myTable[Col4]")
'any changes in the monitored column?
Set rng = Application.Intersect(Target, rngCol)
If Not rng Is Nothing Then '<< got some changes in ColB
Application.EnableEvents = False
For Each c In rng.Cells
If IsNumeric(c.Value) Then
'Update: only apply to values >1
If c.Value > 1 Then c.Value = c.Value / 100000000
End If
Next c
Application.EnableEvents = True
End If
End Sub
(已编辑以显示对Table / ListObject的使用)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.