我在嘗試理解下面的代碼無法正常工作的原因時變得有點瘋狂。查找特定字符串值的範圍內的所有單元格
基本上我有一張表,不同列的貨幣和col B一系列的描述。我正在做的是使用FIND函數來查找'GBP'列和'LCH ISSUE DESCRIPTION'行。我需要兩個單元格中的列和行號('LCH ISSUE DESCRIP.row,GBP.column)我有我需要的信息,並且我將它放在使用SPLIT函數的單獨選項卡中。
問題是'LCH ISSUE DESCRIPTION'在col B中多次出現,這意味着我必須在循環中使用FIND函數。 該代碼對第一個實例工作正常,但不是擊中包含相同值的後續單元格(行),而只是向下移動一行。 任何想法我做錯了什麼?
Sub get_macdata_1()
Dim LastCell As Range, issuerFound As Range
Dim shName As String, issuer As String, ccy As String, inputText As String, firstaddress As String
Dim ccyColumn As Integer, issuerRow As Integer
Dim i As Long, r As Long
Dim splitText As Variant
ccy = "GBP"
issuer = "LCH ISSUE DESCRIPTION"
shName = "December 2014"
ccyColumn = Worksheets(shName).Cells.Find(What:=ccy, LookIn:=xlValues, LookAt:=xlWhole).Column
With Worksheets(shName).Range("B:B")
Set LastCell = .Cells(.Cells.Count)
End With
Set issuerFound = Worksheets(shName).Range("B:B").Find(What:=issuer, After:=LastCell, LookAt:=xlWhole)
If Not issuerFound Is Nothing Then
firstaddress = issuerFound.Address
End If
Do Until issuerFound Is Nothing
issuerRow = issuerFound.Row
inputText = Cells(issuerRow, ccyColumn).Value
splitText = Split(inputText, " ")
r = Worksheets("mac_data").Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
For i = 0 To UBound(splitText)
Sheets("mac_data").Cells(r + 1, i + 1) = splitText(i)
Next i
'Worksheets(shName).Activate
Set issuerFound = Worksheets(shName).Range("B:B").FindNext(After:=issuerFound)
If issuerFound.Address = firstaddress Then
Exit Do
End If
Loop
End Sub
我仍然對你試圖找到哪個值以及一旦你找到它想要做什麼感到困惑。 – iShaymus
我想要查找的值位於貨幣列和「lch發行人描述」行的「笛卡爾積」中。該單元格包含我分割並放入'mac_data'表格中的不同列的各種信息 – yp10