Ẩn hiện Sheet với điều kiện

Liên hệ QC

RAT_LIEU

Thành viên mới
Tham gia
9/9/09
Bài viết
29
Được thích
4
Em có một file gồm nhiều sheet

EM muốn ở bình thường thì các Sheet : One,Two, Three sẽ ẩn
kHI có dữ liệu ở cột c sheet source tương ứng

one: d
two: pe1 hoặc pe2,pe3........
three:b1 hoặc b2.......

thì các sheet này sẽ được hiển thị lên

còn nếu xóa data tương ứng thì sheet tương ứng sẽ hide lại
 

File đính kèm

  • hide-show.xls
    23.5 KB · Đọc: 46
Em có một file gồm nhiều sheet

EM muốn ở bình thường thì các Sheet : One,Two, Three sẽ ẩn
kHI có dữ liệu ở cột c sheet source tương ứng

one: d
two: pe1 hoặc pe2,pe3........
three:b1 hoặc b2.......

thì các sheet này sẽ được hiển thị lên

còn nếu xóa data tương ứng thì sheet tương ứng sẽ hide lại
Bạn làm ơn liệt kê tất cả các trường hợp:
- Gõ chữ gì thì sheet One hiện ra?
- Gõ chữ gì thì sheet Two hiện ra?
- Gõ chữ gì thì sheet Three hiện ra?
 
gõ chữ
d ----> sheet one
pe1 hoặc pe2,pe3,pe4,pe5,p6
b1 hoặc b2.......( một trong các chữ này)----> sheẻt three
Thử code này xem!
PHP:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim dkOne As Boolean, dkTwo As Boolean, dkThree As Boolean
  On Error Resume Next
  If Not Intersect(Range("C:C"), Target) Is Nothing Then
    With Range("C:C")
      dkOne = Not .Find("d", LookAt:=xlWhole) Is Nothing
      dkTwo = Not .Find("pe1", LookAt:=xlWhole) Is Nothing _
           Or Not .Find("pe2", LookAt:=xlWhole) Is Nothing _
           Or Not .Find("pe3", LookAt:=xlWhole) Is Nothing _
           Or Not .Find("pe4", LookAt:=xlWhole) Is Nothing _
           Or Not .Find("pe5", LookAt:=xlWhole) Is Nothing _
           Or Not .Find("pe6", LookAt:=xlWhole) Is Nothing
      dkThree = Not .Find("b1", LookAt:=xlWhole) Is Nothing _
             Or Not .Find("b2", LookAt:=xlWhole) Is Nothing
    End With
    Sheets("One").Visible = dkOne
    Sheets("Two").Visible = dkTwo
    Sheets("Three").Visible = dkThree
  End If
End Sub
 

File đính kèm

  • hide-show(2).xls
    44.5 KB · Đọc: 69
Thử code này xem!
PHP:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim dkOne As Boolean, dkTwo As Boolean, dkThree As Boolean
  On Error Resume Next
  If Not Intersect(Range("C:C"), Target) Is Nothing Then
    With Range("C:C")
      dkOne = Not .Find("d", LookAt:=xlWhole) Is Nothing
      dkTwo = Not .Find("pe1", LookAt:=xlWhole) Is Nothing _
           Or Not .Find("pe2", LookAt:=xlWhole) Is Nothing _
           Or Not .Find("pe3", LookAt:=xlWhole) Is Nothing _
           Or Not .Find("pe4", LookAt:=xlWhole) Is Nothing _
           Or Not .Find("pe5", LookAt:=xlWhole) Is Nothing _
           Or Not .Find("pe6", LookAt:=xlWhole) Is Nothing
      dkThree = Not .Find("b1", LookAt:=xlWhole) Is Nothing _
             Or Not .Find("b2", LookAt:=xlWhole) Is Nothing
    End With
    Sheets("One").Visible = dkOne
    Sheets("Two").Visible = dkTwo
    Sheets("Three").Visible = dkThree
  End If
End Sub

thầy có thể cho em thêm 1 chút hiệu ứng là khi sheet đó hiện lên thì cái tên sheet ở phía dưới nó nhấp nháy được không ạ, cho tơi khi nào chọn qua sheet đó thì nó mới hết nhấp nháy
 
Thử code này xem!
PHP:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim dkOne As Boolean, dkTwo As Boolean, dkThree As Boolean
  On Error Resume Next
  If Not Intersect(Range("C:C"), Target) Is Nothing Then
    With Range("C:C")
      dkOne = Not .Find("d", LookAt:=xlWhole) Is Nothing
      dkTwo = Not .Find("pe1", LookAt:=xlWhole) Is Nothing _
           Or Not .Find("pe2", LookAt:=xlWhole) Is Nothing _
           Or Not .Find("pe3", LookAt:=xlWhole) Is Nothing _
           Or Not .Find("pe4", LookAt:=xlWhole) Is Nothing _
           Or Not .Find("pe5", LookAt:=xlWhole) Is Nothing _
           Or Not .Find("pe6", LookAt:=xlWhole) Is Nothing
      dkThree = Not .Find("b1", LookAt:=xlWhole) Is Nothing _
             Or Not .Find("b2", LookAt:=xlWhole) Is Nothing
    End With
    Sheets("One").Visible = dkOne
    Sheets("Two").Visible = dkTwo
    Sheets("Three").Visible = dkThree
  End If
End Sub
Tôi đã tải file về mà khi nhập d hay pe1 .. thì có thấy sheet nào hiện ra đâu thầy?
 
Web KT
Back
Top Bottom