From 1eb1a7dc874da52575ebd9b40112468049540edf Mon Sep 17 00:00:00 2001 From: Kenichiro NOGI Date: Mon, 14 Sep 2026 09:43:27 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20BuildViewFromSheet=E3=82=92=E3=82=BB?= =?UTF-8?q?=E3=83=AB=E5=BA=A7=E6=A8=99=E6=8C=87=E5=AE=9A=E3=81=8B=E3=82=89?= =?UTF-8?q?=E3=83=86=E3=83=BC=E3=83=96=E3=83=AB=E5=90=8D(FilterTable/Sorte?= =?UTF-8?q?rTable)=E5=8F=82=E7=85=A7=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Filter表・Sorter表の配置をユーザーが移動したところ、固定セル座標(F3/J3)読み取りのため条件が反映されずViewが空になっていた。 ListObjects("FilterTable")/("SorterTable")をテーブル名で取得し、1列目=項目名・2列目=値/昇降順という列位置ベースで読むよう変更。テーブルをシート上のどこに配置しても動作する。 デバッグ用に追加していたリクエストボディ出力ログも削除。 Co-Authored-By: Claude Sonnet 5 --- .../vba-files/Module/Module1.bas | 50 ++++++++++++++----- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/XVBA/新版着工要因閲覧シート/vba-files/Module/Module1.bas b/XVBA/新版着工要因閲覧シート/vba-files/Module/Module1.bas index 24f49de0..466795da 100644 --- a/XVBA/新版着工要因閲覧シート/vba-files/Module/Module1.bas +++ b/XVBA/新版着工要因閲覧シート/vba-files/Module/Module1.bas @@ -302,24 +302,48 @@ Private Function CollectionToArray(Byval col As Collection) As Variant End Function '****************************************************************************** -'{V[gFilter\(F2:G2oAF3ȍ~f[^)ESorter\(H2:I2oAH3ȍ~f[^)ǂݎA -'APINGXgViewp[^ɓnDictionarygݗĂB +'{V[ǵuFilterTablevuSorterTablevƂOExcele[uiListObjectj +'e[uŒTēǂݎAAPINGXgViewp[^ɓnDictionarygݗĂB +'Z̐Έʒuɂ͈ˑȂie[uړĂ삷jBee[u1=ږA2=l/~ƂB 'FilterESorterƂ0̏ꍇNothingԂiViewp[^̂t^Ȃ߁j Function BuildViewFromSheet() As Object Dim colFilter As New Dictionary - Dim r As Long - r = 3 - Do While Trim(defaultSh.Cells(r, "F").Value) <> "" - colFilter.Add defaultSh.Cells(r, "F").Value, "[" & Chr(34) & CStr(defaultSh.Cells(r, "G").Value) & Chr(34) & "]" - r = r + 1 - Loop + Dim filterTbl As ListObject + On Error Resume Next + Set filterTbl = defaultSh.ListObjects("FilterTable") + On Error GoTo 0 + + If Not filterTbl Is Nothing Then + If Not filterTbl.DataBodyRange Is Nothing Then + Dim r As Long + For r = 1 To filterTbl.DataBodyRange.Rows.count + Dim filterKey As String + filterKey = Trim(filterTbl.DataBodyRange.Cells(r, 1).Value) + If filterKey <> "" Then + colFilter.Add filterKey, "[" & Chr(34) & CStr(filterTbl.DataBodyRange.Cells(r, 2).Value) & Chr(34) & "]" + End If + Next r + End If + End If Dim colSorter As New Dictionary - r = 3 - Do While Trim(defaultSh.Cells(r, "J").Value) <> "" - colSorter.Add defaultSh.Cells(r, "J").Value, defaultSh.Cells(r, "K").Value - r = r + 1 - Loop + Dim sorterTbl As ListObject + On Error Resume Next + Set sorterTbl = defaultSh.ListObjects("SorterTable") + On Error GoTo 0 + + If Not sorterTbl Is Nothing Then + If Not sorterTbl.DataBodyRange Is Nothing Then + Dim r2 As Long + For r2 = 1 To sorterTbl.DataBodyRange.Rows.count + Dim sorterKey As String + sorterKey = Trim(sorterTbl.DataBodyRange.Cells(r2, 1).Value) + If sorterKey <> "" Then + colSorter.Add sorterKey, sorterTbl.DataBodyRange.Cells(r2, 2).Value + End If + Next r2 + End If + End If If colFilter.count = 0 And colSorter.count = 0 Then Set BuildViewFromSheet = Nothing