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

回答編集履歴

5

再修正

2020/07/10 17:59

投稿

tosi
tosi

スコア553

answer CHANGED
@@ -8,7 +8,7 @@
8
8
  Dim MyAddr As String
9
9
  Dim MyFormat As String
10
10
  For Each MyRange In Range("E5:E74")
11
- MyAddr = MyRange.Address(RowAbsolute:=True, ColumnAbsolute:=True)
11
+ MyAddr = MyRange.Address
12
12
  MyFormat = "=ISERROR(VLOOKUP(" & MyAddr & ",$X$95:$X$125,1,FALSE))=FALSE"
13
13
  MyRange.FormatConditions.Add Type:=xlExpression, Formula1:=MyFormat
14
14
  MyRange.FormatConditions(1).SetFirstPriority
@@ -43,7 +43,5 @@
43
43
  If blnError = True Then VlookupRevMatch = CVErr(xlErrNA)
44
44
  End Function
45
45
  ```
46
- また、RowAbsolute:=True, ColumnAbsolute:=TrueはFalseより変更しています。
47
- 家のExcelがFalse指定で動作が変になっ為です。
46
+ 、MyRange.Address部分変更しています。
48
- 別のExcelはFalseでも正常なので、個別の問題と思いますが、念の爲変更しています。
49
47
  尚、ユーザー関数は数多く使うと重くなってしまう特徴あります。

4

改行

2020/07/10 17:59

投稿

tosi
tosi

スコア553

answer CHANGED
@@ -21,8 +21,7 @@
21
21
  (追記)
22
22
  基準セル値の中の一部一致で結果を返す事は関数では難しい様に思えます。
23
23
  (データベース関数を使えば出来るのでしょうか・・・・?)
24
- VBAでユーザー関数を作りましたので、これを標準モジュールへ貼り付けてVLOOKUPをVlookupRevMatchに
24
+ VBAでユーザー関数を作りましたので、これを標準モジュールへ貼り付けてVLOOKUPをVlookupRevMatchに入れ替えて動かして見て下さい。
25
- 入れ替えて動かして見て下さい。
26
25
  ```VBA
27
26
  Option Explicit
28
27
  Function VlookupRevMatch( _

3

追記

2020/07/10 03:26

投稿

tosi
tosi

スコア553

answer CHANGED
@@ -44,6 +44,7 @@
44
44
  If blnError = True Then VlookupRevMatch = CVErr(xlErrNA)
45
45
  End Function
46
46
  ```
47
- 、RowAbsolute:=True, ColumnAbsolute:=TrueはFalseより変更しています。
47
+ また、RowAbsolute:=True, ColumnAbsolute:=TrueはFalseより変更しています。
48
48
  家のExcelがFalse指定で動作が変になった為です。
49
- 別のExcelはFalseでも正常なので、個別の問題と思いますが、念の爲変更しています。
49
+ 別のExcelはFalseでも正常なので、個別の問題と思いますが、念の爲変更しています。
50
+ 尚、ユーザー関数は数多く使うと重くなってしまう特徴あります。

2

追記

2020/07/10 03:08

投稿

tosi
tosi

スコア553

answer CHANGED
@@ -8,7 +8,7 @@
8
8
  Dim MyAddr As String
9
9
  Dim MyFormat As String
10
10
  For Each MyRange In Range("E5:E74")
11
- MyAddr = MyRange.Address(RowAbsolute:=False, ColumnAbsolute:=False)
11
+ MyAddr = MyRange.Address(RowAbsolute:=True, ColumnAbsolute:=True)
12
12
  MyFormat = "=ISERROR(VLOOKUP(" & MyAddr & ",$X$95:$X$125,1,FALSE))=FALSE"
13
13
  MyRange.FormatConditions.Add Type:=xlExpression, Formula1:=MyFormat
14
14
  MyRange.FormatConditions(1).SetFirstPriority
@@ -16,4 +16,34 @@
16
16
  Next
17
17
  End Sub
18
18
  ```
19
- 参考Url:[https://teratail.com/questions/267033](https://teratail.com/questions/267033)
19
+ 参考Url:[https://teratail.com/questions/267033](https://teratail.com/questions/267033)
20
+
21
+ (追記)
22
+ 基準セル値の中の一部一致で結果を返す事は関数では難しい様に思えます。
23
+ (データベース関数を使えば出来るのでしょうか・・・・?)
24
+ VBAでユーザー関数を作りましたので、これを標準モジュールへ貼り付けてVLOOKUPをVlookupRevMatchに
25
+ 入れ替えて動かして見て下さい。
26
+ ```VBA
27
+ Option Explicit
28
+ Function VlookupRevMatch( _
29
+ ByRef 検索値 As Range, _
30
+ ByRef 範囲 As Range, _
31
+ ByVal 列番号 As Integer, _
32
+ ByVal 検索方法 As Boolean _
33
+ ) As Variant
34
+ Application.Volatile
35
+ Dim MyRange As Range
36
+ Dim blnError As Boolean: blnError = True
37
+ For Each MyRange In 範囲
38
+ If InStr(検索値, MyRange) <> 0 Then
39
+ VlookupRevMatch = MyRange
40
+ blnError = False
41
+ Exit For
42
+ End If
43
+ Next
44
+ If blnError = True Then VlookupRevMatch = CVErr(xlErrNA)
45
+ End Function
46
+ ```
47
+ 尚、RowAbsolute:=True, ColumnAbsolute:=TrueはFalseより変更しています。
48
+ 家のExcelがFalse指定で動作が変になった為です。
49
+ 別のExcelはFalseでも正常なので、個別の問題と思いますが、念の爲変更しています。

1

行削除

2020/07/10 03:01

投稿

tosi
tosi

スコア553

answer CHANGED
@@ -7,7 +7,6 @@
7
7
  Dim MyRange As Range
8
8
  Dim MyAddr As String
9
9
  Dim MyFormat As String
10
-
11
10
  For Each MyRange In Range("E5:E74")
12
11
  MyAddr = MyRange.Address(RowAbsolute:=False, ColumnAbsolute:=False)
13
12
  MyFormat = "=ISERROR(VLOOKUP(" & MyAddr & ",$X$95:$X$125,1,FALSE))=FALSE"