我在網站上發現了不同的解決方案,但它們不能解決我的問題。以下部分是查找結果,其中「FoundCell」地址返回到工作表。 我正在試圖做的是將「FoundCell」地址返回到單元格(1,1)和其他正下方的其餘部分。我想要我的調試行在電子表格上打印。第一個空單元格
Value Found In Cell: $F$2
Value Found In Cell: $F$5
Value Found In Cell: $F$8
Value Found In Cell: $F$9
頁「計劃指標」載列A至F我使用的查找來搜索列F逗號分隔的字符串目前在字符串代碼返回F列單元格地址找到。我需要什麼樣的條目列與發現地址欄F.相關的&乙
Sub Find()
Dim SearchRange As Range
Dim FoundCells As Range
Dim FoundCell As Range
Dim Destination As Range
Dim c, d As Range
Dim Row As String
Dim FindWhat As Variant
Dim FindWhat2 As Variant
Set Destination = Sheets("Calculations").Cells(1, 1)
Set SearchRange = Sheets("Program Index").Range("F2:F1000")
Debug.Print Sheets("main").Range("F2")
Sheets("Calculations").Range("A2:A50").Clear
FindWhat = Sheets("Main").Range("F2")
FindWhat2 = "All"
Set FoundCells = FindAll(SearchRange:=SearchRange, _
FindWhat:=FindWhat, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
MatchCase:=False, _
BeginsWith:=vbNullString, _
EndsWith:=vbNullString, _
BeginEndCompare:=vbTextCompare)
If FoundCells Is Nothing Then
Debug.Print "Value Not Found"
Else
Set c = Sheets("Calculations").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
For Each FoundCell In FoundCells
c.Value = FoundCell.Address
Set c = c.Offset(1, 0)
Next FoundCell
End If
Set FoundCells = FindAll(SearchRange:=SearchRange, _
FindWhat:=FindWhat2, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
MatchCase:=False, _
BeginsWith:=vbNullString, _
EndsWith:=vbNullString, _
BeginEndCompare:=vbTextCompare)
If FoundCells Is Nothing Then
Debug.Print "Value Not Found"
Else
Set c = Sheets("Calculations").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
For Each FoundCell In FoundCells
c.Value = FoundCell.Address
Set c = c.Offset(1, 0)
Next FoundCell
End If
End Sub
我相信我需要在「的FindAll」應該發生,但是我不知道在哪裏修改變化。
If Not FoundCell Is Nothing Then
Set FirstFound = FoundCell
Do Until False ' Loop forever. We'll "Exit Do" when necessary.
Include = False
If BeginsWith = vbNullString And EndsWith = vbNullString Then
Include = True
Else
If BeginsWith <> vbNullString Then
If StrComp(Left(FoundCell.Text, Len(BeginsWith)), BeginsWith, BeginEndCompare) = 0 Then
Include = True
End If
End If
If EndsWith <> vbNullString Then
If StrComp(Right(FoundCell.Text, Len(EndsWith)), EndsWith, BeginEndCompare) = 0 Then
Include = True
End If
End If
End If
If Include = True Then
If ResultRange Is Nothing Then
Set ResultRange = FoundCell
Else
Set ResultRange = Application.Union(ResultRange, FoundCell)
End If
End If
Set FoundCell = SearchRange.FindNext(after:=FoundCell)
If (FoundCell Is Nothing) Then
Exit Do
End If
If (FoundCell.Address = FirstFound.Address) Then 'modify to find program number and description
Exit Do
End If
Loop
End If
Set FindAll = ResultRange
雙方更好,這是什麼修復完全? – user2140261
我想是個好問題 - 我忽略了這個問題,並根據標題假定OP在定位最後一個單元時遇到了問題,並沒有真正解讀所討論的曲折線。重新閱讀這個問題並不清楚OP想要什麼。 –
謝謝!這就是爲什麼我問我不知道問題是什麼,認爲你發現了我錯過的東西。 – user2140261