![マクロのアドバイス - 特定のセルに「NO」と表示される場合、行を新しいワークシートに貼り付ける](https://rvso.com/image/1502897/%E3%83%9E%E3%82%AF%E3%83%AD%E3%81%AE%E3%82%A2%E3%83%89%E3%83%90%E3%82%A4%E3%82%B9%20-%20%E7%89%B9%E5%AE%9A%E3%81%AE%E3%82%BB%E3%83%AB%E3%81%AB%E3%80%8CNO%E3%80%8D%E3%81%A8%E8%A1%A8%E7%A4%BA%E3%81%95%E3%82%8C%E3%82%8B%E5%A0%B4%E5%90%88%E3%80%81%E8%A1%8C%E3%82%92%E6%96%B0%E3%81%97%E3%81%84%E3%83%AF%E3%83%BC%E3%82%AF%E3%82%B7%E3%83%BC%E3%83%88%E3%81%AB%E8%B2%BC%E3%82%8A%E4%BB%98%E3%81%91%E3%82%8B.png)
VBA とマクロの使用に関するアドバイスをお願いします。
ワークシートをリンクする方法があればいいのですが(ワークシート 1 から 6)をマスターシート(ワークシート 7)。
行に"いいえ"コラムI
全体を通してワークシート 1 から 6)、コードはその行をコピーして貼り付けることができますか?ワークシート 7?
次に、行(ワークシート 1 から 6)は次のように変更されました。"はい" 別のコードでその行を削除できますか?ワークシート 7?
文脈としては、ワークシート 1 から 6仕事のリストと'はい'&'いいえ'クライアントが支払いを済ませた場合です。'いいえ'彼らは債務者リストに追加されますワークシート 7。 もし'はい'彼らは債務者リストから削除される必要がある。
答え1
このコードは以下に役立ちます:
Public Sub debtors()
Dim wkb As Workbook
Dim wks As Worksheet
Dim wksdest As Worksheet
Set wkb = ThisWorkbook
Set wksdest = wkb.Sheets("Sheet7")
wksdest.Rows.Clear 'Clear the contents of Sheet7
destRow = 1 'First row on Sheet7
For i = 1 To 6 'Loop through Sheets 1 to 6
newIndex = Right(Str(i), 1)
thisSheet = "Sheet" + newIndex
Set wks = wkb.Sheets(thisSheet)
wks.Activate
'Selects column I
Columns("I:I").Select
'Find a coincidence with the string "NO"
Set cell = Selection.Find(What:="NO", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
'If there is a coincidence (is Not Nothing)
If Not cell Is Nothing Then
firstRow = cell.Row
newRow = cell.Row
'Copy the row and paste on Sheet7
wks.Rows(newRow).Copy
wksdest.Rows(destRow).PasteSpecial xlPasteValues
destRow = destRow + 1
foundValue = True
'Find next coincidences in the same sheet
While foundValue
Set cell = Selection.FindNext(cell)
If Not cell Is Nothing Then
newRow = cell.Row
If newRow <> firstRow Then
wks.Rows(newRow).Copy
wksdest.Rows(destRow).PasteSpecial xlPasteValues
destRow = destRow + 1
Else
foundValue = False
End If
Else
foundValue = False
End If
Wend
End If
Next i
wksdest.Activate
End Sub
ALT+でVBA/マクロを開きF11、このワークブック新しいモジュールを挿入し、右側にコードを貼り付けます。
緑の三角形をクリックして実行します。
どのように動作するかを理解していただくために、コードにコメントを付けました。
最初の行をクリックしてから を押して各ステップを実行することで、ステップごとに実行することもできますF8。