2016-09-14 7 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 

그래서 기본적으로 나는 다음 시트를 선택하여 그 코드를 반복 희망 말 "손익 계산서"

내가 결과에 대한 희망 코드는 다음과 같은 파일을 가져옵니다.

,451,515,
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 값 (대시)하지 공백을 숨기고해야합니다.

이 코드에 대한 도움을 주셔서 감사합니다.

+0

모든 시트에 대해 위의 스크립트를 반복해서 찾으십니까? 또는 행을 숨기는 데 도움이 필요합니까? 또한 행을 그룹화하는 것으로 나타났습니다 ... 그룹 내에 '숨겨진'행이있는 경우 축소/확장 할 때 '숨김'상태가됩니다. – CRUTER

+0

혼란을 드려 죄송합니다. 분명히 말하면 실제로 "숨김"행을 원하지 않지만보기를 숨기도록 그룹화하고 접을 때 여러 페이지에 대해이 스크립트를 반복 할 수 있기를 원합니다. 감사! – 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 대신에 자신의 논리를 삽입합니다. 출력 형식이 일관되면 카테고리 행을 마지막에 ':'문자 (예 : '자산 :', '부채 :'등)가있는 항목으로 정의하고 다음 행으로 건너 뛸 수 있습니다.