2016-09-14 3 views
0

私はこのファイルを使用していますので、大量の入力を入れています。すべての入力を確定した後、出力タブのカテゴリがまだ空白であるか、カテゴリのサブタイトルがOPEN(つまり、そのサブタイトルにセクションを割り当てたことはありません。その行を非表示にして複数の出力用紙複数のシートの特定の条件に基づいてExcelで行を非表示にしようとしています

私が持っている現在のコードは次のとおりです。

Sub Group_And_Hide() 
' 
' Group_And_Hide Macro 
' 

' 
'Define Variables 
    Dim myRange As Range 
    Dim rowCount As Integer, currentRow As Integer 
    Dim firstZeroValueRow As Integer, lastZeroValueRow As Integer 
    Dim CurrentRowValue As String 
    Dim neighborColumnValue1 As String 
    Dim NGV2 As String 
    Dim NGV3 As String 
    Dim NGV4 As String 
    Dim NGV5 As String 
    Dim CheckColumn As Integer 


'Select Balance Sheet 
Sheets("Balance Sheet").Select 
Application.ScreenUpdating = False 'Turns off screen uppdating while running 

'Establish the page range 
Set myRange = Range(D3, W126) 
rowCount = Cells(Rows.Count, myRange.Column).End(xlUp).Row 

'Reset the rows and Check 
firstZeroValueRow = 0 
lastZeroValueRow = 0 
CheckColumn = 9 

'Commands 
    For currentRow = 1 To rowCount 
     CurrentRowValue = Cells(currentRow, myRange.Column).Value 
     neighborColumnValue = Cells(currentRow, myRange.Column - 1).Value 

     If Cells(currentRow, CheckColumn).Value Like "**OPEN**" Then 
      'If First Cell is Open, and first blank row hasn't been assigned 
      If firstZeroValueRow = 0 Then 
       firstZeroValueRow = currentRow 
      End If 
     ElseIf Not Cells(currentRow, CheckColumn).Value Like "**OPEN**" Then 
      'if the cell is not Open and the row right values are 0, 
      'and firstBlankRow hasn't been assigned, then this is the  firstBlankRow 
      'to consider for grouping 
      If (Cells(currentRow, CheckColumn + 3).Value And Cells(currentRow, CheckColumn + 4).Value And Cells(currentRow, CheckColumn + 5).Value And Cells(currentRow, CheckColumn + 6).Value = 0) Then 

       firstZeroValueRow = currentRow 
      ElseIf Cells(currentRow, CheckColumn + 3).Value And Cells(currentRow, CheckColumn + 4).Value And Cells(currentRow, CheckColumn + 5).Value And Cells(currentRow, CheckColumn + 6).Value <> 0 And firstZeroValueRow <> 0 Then 
       'if firstBlankRow is assigned and this row has a value with a neighbor 
       'who isn't 0, then the cell one row above this one is to be considered 
       'the lastBlankRow to include in the grouping 
       lastZeroValueRow = currentRow - 1 
      End If 
     End If 

     'if first AND last blank rows have been assigned, then create a group 
     'then reset the first/lastBlankRow values to 0 and begin searching for next 
    'grouping 
    If firstZeroValueRow <> 0 And lastZeroValueRow <> 0 Then 
     Range(Cells(firstZeroValueRow, myRange.Column), Cells(lastZeroValueRow, myRange.Column)).EntireRow.Select 
     Selection.Group 
     firstZeroValueRow = 0 
     lastZeroValueRow = 0 
    End If 
Next 




ActiveSheet.Outline.ShowLevels RowLevels:=1 'Minimize all the groups 
Application.ScreenUpdating = True 'Turns on screen updating when done 


End Sub 

だから、基本的に、私は次のシートを選択することで、そのコードを繰り返すために望んでいるだろうと言う「損益計算書」

私は結果を期待コードは次のようなファイルをとります:

Assets: 
Current Assets 4000 50000 60000 
Fixed Assets  100  8000 500 
Liabilities: 
C. Liab.   -  -  - 
LT Liab.   -  -  - 
Equity: 
Capital Stock  4100 58000 60500 
**OPEN**   -  -  - 
Net Income  (300) (100) (500) 
RE    300  100 500 

そして、それはこのように見て終わるでしょう:

Assets: 
Current Assets 4000 50000 60000 
Fixed Assets  100  8000 500 
Liabilities: 
Equity: 
Capital Stock  4100 58000 60500 
Net Income  (300) (100) (500) 
RE    300  100 500 

だから私はゼロ値(ダッシュ)ではない空白を非表示にする必要があります。

このコードのお手伝いをしていただきありがとうございます。

+0

上記のスクリプトをすべてのシートに対して繰り返していますか?または、行を隠すのに役立つ必要がありますか?また、あなたが行をグループ化していることに気付きました。あなたのグループ内に「隠れた」行がある場合、それを折りたたむ/展開すると「非表示」になります。 – CRUTER

+0

を混乱させて申し訳ありません。明確にするために、私は実際には1行あたりの行を非表示にしたくないのですが、それらをグループ化して折りたたんで表示しないようにしたいので、複数のページでこのスクリプトを繰り返すことができます。ありがとう! – BotBadger112233

答えて

0

CRUTERがコメントしたように、行をグループ化すると、行を非表示にする目的が無効になります。グループを開くと、非表示の行が表示されます。

出力の行を非表示にして忘れてしまった場合は、行を繰り返し繰り返し、条件を満たすものを隠すことをおすすめします。以下のような何か:

For RowIndex = 1 To LastRow 
    If (Not IsCategoryRow(RowIndex)) Then 
     If (IsRowEmpty(RowIndex)) Then 
      Rows(RowIndex).EntireRow.Hidden = True 
     End If 
    End If 
Next RowIndex 

あなたの出力の最後であることをLastRowを定義し、IsCategoryRowIsRowEmptyの代わりに独自のロジックを挿入します。出力形式が一貫している場合は、カテゴリ行を最後に「:」文字(たとえば「資産:」、「負債:」など)を指定して定義し、次の行にスキップするだけです。

関連する問題