当16--24整列选择时,通过find查找的单元格firstCol和endCol列号都是20(查找到的都是黄色单元格); 而当选择的并非整列时, 通FIND查找到的单元格的列号是正确的17/21.
Sub km()
Dim rng As Range
Set rng = Range(Cells(1, 16), Cells(Rows.count, 25))
Set rngFirst = rng.Cells(1, 1)
If rngFirst.Value & "" <> "" Then
Set FirstRow = rngFirst
Set firstCol = rngFirst
Else
Set FirstRow = rng.Find(What:="?", After:=rngFirst, LookIn:=-4185, LookAt:=2, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, MatchByte:=False, SearchFormat:=False)
Set firstCol = rng.Find(What:="?", After:=rngFirst, LookIn:=-4185, LookAt:=2, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False, MatchByte:=False, SearchFormat:=False)
End If
Set rngEnd = rng.Cells(rng.Rows.count, rng.Columns.count)
If rngEnd.Value & "" <> "" Then
Set endRow = rngEnd
Set endCol = rngEnd
Else
Set endRow = rng.Find(What:="?", After:=rngEnd, LookIn:=-4185, LookAt:=2, _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False, MatchByte:=False, SearchFormat:=False)
Set endCol = rng.Find(What:="?", After:=rngEnd, LookIn:=-4185, LookAt:=2, _
SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False, MatchByte:=False, SearchFormat:=False)
End If
End Sub
|