ワークシート A で (文字列)を受け取るマクロを作成し、cell.value
ワークシート B に移動し、cells.find
メソッドを使用して文字列に一致するセルを見つけます。
例
SheetA.activecell.value = "Harry Potter"
set myvar = SheetA.activecell.value
sheetB.select
Cells.Find(What:=myvar, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Select
上記の構文が正しいと仮定すると、文字列「Harry Potter」を含むワークシート A のセルが自動的に選択されます。
Cells.Find
ここで問題が発生します。列全体をループして、列内の各セルに対して関数を実行したいと考えています。
たとえば、SheetA.cells(3 ,1)
「ハリー・ポッター」が含まれます。ループが完了するたびにオフセット関数を使用すると、検出する値を含むセルが 1 行ずつオフセットされます。
そのため、ループの次の反復では、Cells(4, 1)
SheetA にcells.find
関数で使用される値が含まれます。
たとえば、その値は文字列「Iphone Charger」です。次に、ワークシート B で cells.find(what:=myvar (基本的に myvar = "Iphone Charger") が実行されます。
ワークシート A の列も同様です。
次に、ワークシート A の特定の値をコピーしたいと考えています。
シナリオ:
If "Harry Potter" is found in sheetA then
Do an `activecell.offset` function to copy some values in the same row as the cell in sheet A and
Copy those values to worksheet B using Copy destination
Else if "Harry Potter" can be found then
Jump to the next cell value.
End if
Keep looping until worksheet B hits an empty cell, that is cells(X , 1).value = ""
Then the whole macro ends
この問題を解決するために私の脳細胞を殺しており、このフォーラムの誰かが私を助けてくれれば幸いです.