3
我目前遇到與宏有關的問題我正在爲Excel 2013編程有關讀取隱藏列的問題。我正在嘗試利用列A作爲一行唯一鍵,以便快速開發基於列A中的鍵值隱藏和顯示行的邏輯。當我在表單中手動隱藏列A以實現視覺目的時,無法讀取該列,又名我的代碼返回錯誤。如果我顯示該列的代碼執行清楚。先謝謝您的幫助!在Excel 2013中使用VBA讀取隱藏列的問題
Public Sub hideRow(findId As String, sheetName As String)
Dim lastRow As Long
Dim foundCell As Range
Dim hideThisRowNum As Integer
'Get Last Row
lastRow = Worksheets(sheetName).Range("A" & Rows.Count).End(xlUp).Row
'Find ID
With Worksheets(sheetName).Range("a1:a1000") 'This needs to be A1 to AxlDown
Set foundCell = Worksheets(sheetName).Range("A1:A" & lastRow).Find(What:=findId, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
End With
'Get Row # to Hide
hideThisRowNum = Val(foundCell.Row)
'Hide row
Worksheets(sheetName).Rows(hideThisRowNum).Hidden = True
'Set Add To Action Plan = No
Worksheets(sheetName).Range("G" & hideThisRowNum).Value = "No"
End Sub
謝謝,這照顧到了這個問題。你爲我節省了一個小時左右的困惑,因爲我是全新的VB。 – JeffreDodd