Advertisement
Guest User

Yritys

a guest
Jan 31st, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub Alusta()
  2. ' Tämä ajetaan 1. välilehdelle ja vain kerran
  3.  For i = 12 To 34
  4.     t = Cells(i, 1).Top
  5.     h = Cells(i, 1).Height
  6.     ActiveSheet.CheckBoxes.Add(6, t, 20, h).Select
  7.     Selection.Name = "ChkBox" & i
  8.     Selection.Text = ""
  9.     Selection.OnAction = "Piilota"
  10.   Next i
  11. End Sub
  12.  
  13.  
  14. Sub KaikkiNäkyviin()
  15. ' Nappiin kytketty makro
  16.  Rows("12:34").Hidden = False
  17.   Application.EnableEvents = False
  18.   For i = 12 To 34
  19.     ActiveSheet.CheckBoxes("ChkBox" & i).Visible = 1
  20.     Rows(i).Hidden = fase
  21.   Next i
  22.  
  23.   Application.EnableEvents = True
  24. End Sub
  25.  
  26.  
  27. Sub Piilota()
  28.   For i = 12 To 34
  29.    If ActiveSheet.CheckBoxes("ChkBox" & i).Value = 1 Then
  30.      ActiveSheet.CheckBoxes("ChkBox" & i).Value = 0
  31.      ActiveSheet.CheckBoxes("ChkBox" & i).Visible = 0
  32.      Rows(i).Hidden = True
  33.      Call Tarkista("Sheet2", i)
  34.      ' Call Tarkista("Sheet3", i) ' jne.
  35.     Exit Sub
  36.    End If
  37.   Next
  38. End Sub
  39.  
  40. Sub Tarkista(Sivu, r)
  41.   For rr = 1 To Sheets(Sivu).Range("A1").SpecialCells(xlCellTypeLastCell).Row
  42.     Löytyi = True
  43.     For c = 2 To Cells(r, Sheets(Sivu).Columns.Count).End(xlToLeft).Column
  44.       If Cells(r, c) <> Sheets(Sivu).Cells(rr, c) Then
  45.         Löytyi = False
  46.         Exit For
  47.       End If
  48.     Next c
  49.     If Löytyi Then
  50.       Sheets(Sivu).Rows(rr).Hidden = True
  51.       Exit Sub ' Tämä rivi pois, jos sivuilla voi olla useampia samanlaisia rivejä
  52.    End If
  53.   Next rr
  54. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement