iT邦幫忙

0

excel 用vba隱藏欄位求救

  • 分享至 

  • xImage

如何根據A column中若為空白則隱藏該row,A column以外至E column的內容隱藏起來
https://ithelp.ithome.com.tw/upload/images/20201126/20117357jzlXXOgriU.png
變為
https://ithelp.ithome.com.tw/upload/images/20201126/20117357Jxv5Uug7yz.png

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

1
rogeryao
iT邦超人 8 級 ‧ 2020-11-26 16:09:44
最佳解答
Private Sub CommandButton1_Click()
'B,C,D 欄位隱藏
Range(Columns(2), Columns(4)).Hidden = True
'
Dim U As Integer
Set RngHead = Range("A1")
DataCunt = Range("A65536").End(xlUp).Row
'A 欄位值空白隱藏
For U = RngHead.Row To DataCunt
  If (Trim(Cells(U, 1)) = "") Then
    Rows(U).Hidden = True
  End If
Next
End Sub
0
race
iT邦新手 5 級 ‧ 2020-11-26 18:47:07

先確認資料的範圍,再Loop記錄Row,進行處理.Column則直接處理

Sub Test()
    Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
    Columns("B:D").Hindden = True
end sub    
race iT邦新手 5 級 ‧ 2020-11-26 18:48:51 檢舉

錄製巨集,也應該可以得到答案

我要發表回答

立即登入回答