Dim Sht1 As Worksheet
Dim Sht2 As Worksheet
Dim LastRow As Long
Dim i As Long
Dim J As Long
Dim SearchWord As String
Set Sht1 = Sheets("計算")
Set Sht2 = Sheets("新宿")
SearchWord = "新宿"
Sht1.Select
J = 2
LastRow = Sht1.Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To LastRow
If InStr1(Cells(i, 1), SearchWord) > 0 Then
Sht1.Range(Cells(i, 1), Cells(i, 3)).Copy Sht2.Cells(J, 1)
J = J + 1
End If
Next i
1Sub Macro1()
23 Dim Sht1 As Worksheet
4 Dim Sht2 As Worksheet
5 Dim LastRow As Long
6 Dim i As Long
7 Dim j As Long
8 Dim SearchWord As String
91011 SearchWord = InputBox("どこ?", "会場入力", "新宿")
1213 Set Sht1 = Sheets("計算用")
14 Set Sht2 = Sheets(SearchWord)
1516 Dim arr, k
17 arr = Sht1.UsedRange.Resize(1).Value
18 For k = 1 To UBound(arr, 2)
19 arr(1, k) = IIf(WorksheetFunction.CountIf(Sht2.Rows(2), arr(1, k)) > 0, WorksheetFunction.Match(arr(1, k), Sht2.Rows(2), False), 0)
20 Next
2122 j = 2
23 LastRow = Sht1.Cells(Rows.Count, 2).End(xlUp).Row
24 For i = 2 To LastRow
25 If InStr(Sht1.Cells(i, 2), SearchWord) > 0 Then
26 For k = 1 To UBound(arr, 2)
27 If arr(1, k) > 0 Then Sht2.Cells(j, arr(1, k)).Value = Sht1.Cells(i, k).Value
28 Next
29 j = j + 1
30 End If
31 Next i
32 Sht2.Cells.Rows(3).Copy
33 Sht2.Cells.Rows(3).Resize(j - 2).PasteSpecial Paste:=xlPasteFormats
3435End Sub
3637
(再々々々修正)
VBA
1Sub Macro2()
23 Dim Sht1 As Worksheet
4 Dim Sht2 As Worksheet
5 Dim LastRow As Long
6 Dim i As Long
7 Dim j As Long
8 Dim SearchWord As String
91011 Set Sht1 = Sheets("計算用")
12 LastRow = Sht1.Cells(Rows.Count, 2).End(xlUp).Row
13 For i = 2 To LastRow
14 Set Sht2 = Sheets(Sht1.Cells(i, "C").Value)
15 j = Sht2.Cells(Rows.Count, 2).End(xlUp).Row + 1
16 Dim k, v
17 For k = 2 To Sht2.Cells(2, Columns.Count).End(xlToLeft).Column
18 v = WorksheetFunction.Clean(Sht2.Cells(2, k).Value)
19 If WorksheetFunction.CountIf(Sht1.Rows(1), v) > 0 Then
20 Sht2.Cells(j, k).Value = Sht1.Cells(i, WorksheetFunction.Match(v, Sht1.Rows(1), False)).Value
21 End If
22 Next k
23 Sht2.Cells.Rows(3).Copy
24 Sht2.Cells.Rows(j).PasteSpecial Paste:=xlPasteFormats
25 Next i
2627 For i = 2 To LastRow
28 Set Sht2 = Sheets(Sht1.Cells(i, "D").Value)
29 j = Sht2.Cells(Rows.Count, 2).End(xlUp).Row + 1
30 Dim k
31 For k = 2 To Sht2.Cells(2, Columns.Count).End(xlToLeft).Column
32 v = WorksheetFunction.Clean(Sht2.Cells(2, k).Value)
33 If WorksheetFunction.CountIf(Sht1.Rows(1), v) > 0 Then
34 Sht2.Cells(j, k).Value = Sht1.Cells(i, WorksheetFunction.Match(v, Sht1.Rows(1), False)).Value
35 End If
36 Next k
37 Sht2.Cells.Rows(3).Copy
38 Sht2.Cells.Rows(j).PasteSpecial Paste:=xlPasteFormats
39 Next i
40End Sub
41
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/07/28 10:20
2021/07/28 13:45
2021/07/29 01:37
2021/07/29 02:55 編集
2021/07/29 03:00
2021/07/29 03:09
2021/07/29 03:18
2021/07/29 03:23
2021/07/29 03:35
2021/07/29 03:41
2021/07/29 03:48
2021/07/29 03:49
2021/07/29 03:50
2021/07/29 03:53
2021/07/29 04:02