以下に私のコードをコメントしました。現在のワークブックをループして、青い境界線のあるセルを検索しようとしています(現在、列Aでのみテストしています)。
セルに青い境界線がある場合は、2番目のワークブックで一致するセルを見つけたいと思います(範囲は常に列Aになり、2番目のワークブックは常に一致する値を持つ必要があります)。
一致が見つかったら、一致が見つかったのと同じ行で、次に使用可能な列の1番目のブック(フォーマットを含む)から2番目のブックに値を返します。ほとんどの場合、列Bだけになりますが、列Bが入力されている場合は、列Cなどに移動します。
一致関数が機能し、正しいidCella.valueを返します。
resultMは一致の正しい行が見つかったと言っていますが、続行する方法がわかりません。
.offset(0,1)
resultMが必要なことはわかっていますが、何かが足りず、何がわからないのです。
説明がお役に立てば幸いですが、さらに情報が必要な場合はお知らせください。
編集:完全に一致するものを見つけると言うと、2番目のブックの値は同じ青いborder /interior.colorを持ちません。cell.valueの一致を見つけたいだけです。それは言うのは冗長かもしれませんが、私はそれを追加すると思いました。まだ勉強してる :)。
Dim testWS As Worksheet
Dim testRange As Range, rr2Dest As Range, idCella As Range
Dim alastRow2 As Long, resultM As Long
Set testWS = Workbooks("Test.xlsx").Worksheets("October") 'set the 2nd workbook as testWS
Set testRange = testWS.Columns(1) 'searching only column A on testWS (2nd workbook)
alastRow2 = Worksheets("Reruns To Pull").Cells(Rows.Count, "A").End(xlUp).Row 'find last row in column A that has data on current workbook
For Each idCella In Worksheets("Reruns To Pull").Range("A1:A" & alastRow2).Cells 'for each cell in Column A on current workbook (eventually I want to loop through Column A, D, G, J. All will be variable ranges)
If idCella.Borders.Color = RGB(0, 0, 192) Then 'On current workbook, if cells in Col A borders.color = blue then
resultM = Application.Match(idCella.Value, testRange, 0) 'find exact match on Test.xlsx (2nd workbook) and store in variable resultM
'look up value is the first cell found on current workbook that has blue border
'the range I want to search is column A of Test.xlsx
Set rr2Dest.Value = resultM 'trying to set this result to a variable so I can offset the range location by 1 column (Result from current workbook goes to Column B on Tets.xlsx workbook)
rr2Dest.Value = idCella.Value
rr2Dest.Interior.Color = idCella.Interior.Color 'everything I want to transfer into Column B on the 2nd workbook
rr2Dest.Borders.Color = idCella.Borders.Color
rr2Dest.Borders.Weight = idCella.Borders.Weight
End If
Next idCella
End Sub```
Set rr2dest = testWS.Range("A" & CStr(resultM)).Offset(0, 1)
問題を解決しました。マクロがどのワークブックにあるかを追跡していないことに気づいていませんでした。したがって、それを指定してCStr
、一致を含む変数と組み合わせて使用した後。
シュットの答えを投げるだけでいいのです。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加