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

回答編集履歴

1

コメントに基づき、Private Function get_weekの内容を修正しました。

2019/11/12 14:55

投稿

tatsu99
tatsu99

スコア5540

answer CHANGED
@@ -12,8 +12,10 @@
12
12
  ```VBA
13
13
  Private Function get_week(ws As Worksheet, lastrow As String, key As String) As String
14
14
  Dim wrow As Long
15
+ Dim result As Variant
15
16
  For wrow = 2 To CLng(lastrow)
16
- If InStr(ws.Cells(wrow, "A").Value, key) > 0 Then
17
+ result = Cells(wrow, "A").Value Like key & "*Total"
18
+ If result = True Then
17
19
  get_week = ws.Cells(wrow, "B").Value
18
20
  Exit Function
19
21
  End If