简体   繁体   English

根据不同的单元格隐藏多个行范围

[英]Hide multiple range of rows based on differents cell

Currently i have a working script exept that it is a bit slow due to the fact that it is hidding row 1 by 1 when i actually need to hide 58 rows per loop, i know it is possible to hide a range of loop and made it work but only for the first 58 rows, dosen't hide the next 58. There is in total 1740 rows so i am hidding up to 1740 time instead of 30 time.目前我有一个工作脚本,但它有点慢,因为当我实际上需要每个循环隐藏 58 行时它隐藏了 1 行 1 行,我知道可以隐藏一系列循环并成功工作,但仅适用于前 58 行,不要隐藏接下来的 58 行。总共有 1740 行,所以我最多隐藏 1740 次而不是 30 次。

So the goal of the script is to hide rows as to not print this part of the worksheet, there is in total 30 sheet of paper that can be printed in this worksheet.所以脚本的目标是隐藏行以不打印工作表的这一部分,该工作表中总共可以打印 30 张纸。 each sheet is 58 row and what determine if the sheet is to be printed is if cell I3, for the first sheet, have a text or if it is emtpy or have a space, the next sheet is I63, then I119 and so on.每张纸是 58 行,决定是否要打印这张纸的是单元格 I3,对于第一张纸,是否有文本,或者它是否为空或有空格,下一张纸是 I63,然后是 I119,依此类推。

在此处输入图像描述

the code in question is this one and is working by hiding row 1 by 1 :有问题的代码是这个代码,并且通过 1 隐藏第 1 行来工作:

Sub Hide_column_and_Row_FR_3_XX_Fiche_Erreur()

Dim NbreLigne As Integer
Dim hh As Variant
Dim zz As Variant
Dim tableau As range


Set wrkshtDoc = ActiveWorkbook.Worksheets("FR-3-XX_Fiche d'erreur")
Set tableau = wrkshtDoc.range("A1:L1740")
hh = 1

NbreLigne = tableau.Rows.Count

For k = 3 To NbreLigne

            If tableau(k, 9) = " " Or tableau(k, 9) = Empty Then
               For zz = 1 To 58
               wrkshtDoc.Rows(hh).Hidden = True
               hh = hh + 1
               Next zz
                  
            Else
               For zz = 1 To 58
               wrkshtDoc.Rows(hh).Hidden = False
               hh = hh + 1
               Next zz
            End If
        
        k = k + 57
          
Next k

End Sub结束子

I tried different way to select multiples rows but i alway end up being block behind ''missing object''.我尝试了不同的方法来选择多行,但我总是被“丢失的对象”挡在后面。 i can do code inside a cell in a worksheet but VBA is a different thing... i tried to reuse as much code as possible that was already in this document to make something...我可以在工作表中的单元格内编写代码,但 VBA 是另一回事......我试图尽可能多地重用本文档中已经存在的代码来制作一些东西......

Thanks.谢谢。

Use Step to step 58 rows at a time and Resize to pick up all 58 rows:使用 Step 一次步进 58 行并使用 Resize 拾取所有 58 行:

Sub Hide_column_and_Row_FR_3_XX_Fiche_Erreur()

    Dim NbreLigne As Long
    Dim tableau As Range
    
    
    Set wrkshtDoc = ActiveWorkbook.Worksheets("FR-3-XX_Fiche d'erreur")
    Set tableau = wrkshtDoc.Range("A1:L1740")
    
    NbreLigne = tableau.Rows.Count
    
    Dim k As Long
    For k = 3 To NbreLigne Step 58
        tableau(k, 9).Resize(58, 1).EntireRow.Hidden = (tableau(k, 9) = " " Or tableau(k, 9) = Empty)
    Next k
End Sub

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

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