首页 > 解决方案 > 创建一个可以在多个工作表上运行的 VBA 宏

问题描述

我正在尝试制作一个调用其他宏(如下面的宏)并将它们应用于指定工作表的宏。

我认为问题在于我之前制作的它调用的宏没有正确编码以应用于它不活跃的工作表。

这是我的代码:

Sub limits_Monitoring_bores()

        Dim sht As Worksheet, lastRow As Long
        Set sht = ActiveWorkbook.Worksheet

'Name columns appropriately


 With ActiveWorkbook.Worksheets(1)
    .Cells(1, 4).Value = "Min"
    .Cells(1, 5).Value = "Max"
    .Cells(1, 7).Value = "20th Percentile"
    .Cells(1, 8).Value = "80th Percentile"
    .Cells(1, 10).Value = "20th Percentile"
    .Cells(1, 11).Value = "80th Percentile"

End With

        lastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row
        sh.Range("D2:D" & lastRow).Value = "=6"
        sh.Range("E2:E" & lastRow).Value = "=8.5"
        sh.Range("G2:G" & lastRow).Value = "=PERCENTILE(F:F,0.2)"
        sh.Range("H2:H" & lastRow).Value = "=PERCENTILE(F:F,0.8)"
        sh.Range("J2:J" & lastRow).Value = "=PERCENTILE(I:I,0.2)"
        sh.Range("K2:K" & lastRow).Value = "=PERCENTILE(I:I,0.8)"

标签: excelvba

解决方案


推荐阅读