将除法公式应用于Excel宏中的整个列?

时间:2019-04-26 17:30:33

标签: excel vba

我不仅要将此公式应用于B2单元格,而且要应用于整个B列。

       constructor(private router: Router) {
        router.events.subscribe(() => shouldGetDresses());
       }

       private shouldGetDresses() {
        this.dressService.getDresses().subscribe(res => {
        this.dress = res;
       });
      }

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

类似这样的东西:

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的使用)