teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

誤字の修正

2019/09/18 23:22

投稿

mattuwan
mattuwan

スコア2167

answer CHANGED
@@ -5,6 +5,8 @@
5
5
 
6
6
 
7
7
  ```ExcelVBA
8
+ Option Explicit
9
+
8
10
  Sub test()
9
11
  Dim rngKey As Range
10
12
  Dim rngFind As Range
@@ -13,15 +15,15 @@
13
15
  Dim ix As Long
14
16
 
15
17
  Set rngKey = ActiveCell
16
- sKey = rnkey.Value
18
+ sKey = rngKey.Value
17
- With ActiveSheet.UsedRange
19
+ With ActiveSheet
18
- Set rngFind = Range(rngKey, Cells(Rows.Count, "LHL").End(xlUp))
20
+ Set rngFind = .Range(rngKey, .Cells(.Rows.Count, "LHL").End(xlUp))
19
21
  End With
20
22
 
21
23
  For Each r In rngFind.Rows
22
24
  ix = 0
23
25
  On Error Resume Next
24
- ix = WorksheetFunction.Match(s, rngFind.Cells, 0)
26
+ ix = WorksheetFunction.Match(sKey, rngFind.Cells, 0)
25
27
  On Error GoTo 0
26
28
 
27
29
  With r.Cells(1)
@@ -33,6 +35,7 @@
33
35
  End With
34
36
  Next
35
37
  End Sub
38
+
36
39
  ```
37
40
  で見つかれば0より大きい答えが返ってきますし、
38
41
  見つからなければ、エラーとなり、その行の実行は無視して、