繁体   English   中英

如果可能,使用 VBA 或任何 excel 公式单击按钮,从 excel 工作表中删除 n% 的行

[英]Delete n% of the rows from the excel sheet on click of the button using VBA or any excel formula if possible

我想从 sheet1、sheet2、sheet3、sheet4 中删除 n% 的单元格。 百分比将在工作表名称中以原始形式给出。 例如,在 E19 的原始工作表中,它给定了 10%,因此在每张工作表 S1、S2、S3、S4 中,它应该删除总共 10% 的数据行。 (示例:工作表 1 有 100 行数据,因此按照 10%,它应该从 100 行中删除 10 行,其他工作表也类似。我研究了很多但没有得到任何与此相关的信息。

要删除前 x% 的行,您可以这样做:

s.Range(s.Cells(1, 1), s.Cells(s.UsedRange.Rows.Count * Range("Percentage").Value, 1)).EntireRow.Delete

其中范围(“百分比”)是给出百分比的单元格

要为所有工作表获取它,您只需要一个循环来重复:

Sub deleteFirstPercentageOfRows()
Dim s As Worksheet
    For Each s In ThisWorkbook.Sheets
        If s.Name <> "raw" Then
            s.Range(s.Cells(1, 1), s.Cells(s.UsedRange.Rows.Count * Range("Percentage").Value, 1)).EntireRow.Delete
        End If
    Next s
End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM