Page 1 of 1

การซ่อนคอลัมภน์

Posted: Sat Dec 17, 2011 8:30 am
by niwat2811

Code: Select all

Sub HideRows()
    Dim cell As Range
    Dim AllCell As Range
    With Sheets("Sheet1")
        Set AllCell = .Range("A1", .Range( _
            "A" & Rows.Count).End(xlUp))
    End With
    For Each cell In AllCell
        If cell = 0 Then
            cell.EntireRow.Hidden = True
        End If
    Next
End Sub
จาก Code ด้านบนถ้าเราต้องการซ่อนคอลัมภน์ใช้ Code ด้านล่างนี้จะได้ไหมครับท่านอาจารย์

Code: Select all

Sub HideColumns()
    Dim cell As Range
    Dim AllCell As Range
    With Sheets("Sheet1")
        Set AllCell = .Range("A1", .Range( _
            "A" & Columns.Count).End(xlLeft))
    End With
    For Each cell In AllCell
        If cell = 0 Then
            cell.EntireColumn.Hidden = True
        End If
    Next
End Sub

Re: การซ่อนคอลัมภน์

Posted: Sat Dec 17, 2011 9:27 am
by snasui
:D ใช่แล้วครับ แต่ให้เปลี่ยน .end(xlleft) เป็น .end(xltoleft) ครับ

Re: การซ่อนคอลัมภน์

Posted: Sat Dec 17, 2011 12:21 pm
by niwat2811
ขอบคุณครับท่านอาจารย์