我目前遇到宏问题我正在为Excel 2013编写有关阅读隐藏列的问题。我正在尝试将A列用作一行唯一键,以便我能够快速开发隐藏的逻辑,并根据A列中的键值显示一行。当我在工作表中手动隐藏A列用于视觉目的时,我就是无法从该列读取,也就是我的代码返回错误。如果我显示列,代码执行清楚。在此先感谢您的帮助!
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
答案 0 :(得分:4)
问题出在.Find()调用中。使用LookIn:=xlValues
将找不到隐藏的单元格。将其更改为LookIn:=xlFormulas
,它应该可以正常工作。