| すぐマク YNxv9824 | Home | Search | Contents | Gallery | Introduction | Service | Support | What's New! |
| A列に特定の数字が入っている行を抽出してコピーするには? |
|
|
|||||
|
はじめまして、こんにちは。 EXCEL VBA初心者なので、とんでもない初歩的な質問をします。 データの中にあるA列から、特定の数字が入っている行全体のみ別シートに貼り付けたいのです。 IF文でいけると思うのですが、なかなかできません。 教えていただければと思います。 |
|
|||
|
こんにちは、もてもてです。 If文を使うならこんな感じでしょうか。(FindNextというのもあります。ヘルプを見てみましょう。) |
|||
Sub test()
Dim stRow As Integer
Dim endRow As Long
Dim WriteRow As Long
Const Find_Word = "abc" '検索文字
Const Read_Sheet = "Sheet1" '検索Sheet
Const Write_Sheet = "Sheet2" '書込みSheet
'
Sheets(Read_Sheet).Select
endRow = Cells(65536, 1).End(xlUp).Row '最終行
stRow = Cells(1, 1).End(xlDown).Row '開始行
If endRow = stRow Then
stRow = 1
End If
'
WriteRow = 1 '書き出し
For i = stRow To endRow
If Cells(i, 1) Like "*" & Find_Word & "*" Then
Rows(i).Copy
Sheets(Write_Sheet).Rows(WriteRow).PasteSpecial
Application.CutCopyMode = False
WriteRow = WriteRow + 1
End If
Next i
End Sub
|
|
|||||
| ありがとうございます。データ抽出ができました。 |
| http://www.geocities.jp/happy_ngi/ | Home | Contents | Gallery | Introduction | Service | Support | What's New! |