From fd70fb4f8d86a59f565286544c8e1cb8e010f902 Mon Sep 17 00:00:00 2001 From: updsv7 Date: Mon, 13 Apr 2026 17:34:39 +0900 Subject: [PATCH] Z1 CSV import - validate all rows first, map CSV 1-7 to C-I --- vba_code_kotsu_master.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/vba_code_kotsu_master.txt b/vba_code_kotsu_master.txt index c25225d..b0c9235 100644 --- a/vba_code_kotsu_master.txt +++ b/vba_code_kotsu_master.txt @@ -46,8 +46,10 @@ Sub ImportMasterDetailData() lines = Split(textContent, vbLf) - ' === Validate data rows - must have exactly 7 columns === + ' === First: validate all data rows have exactly 7 columns === + Dim validRowCount As Long Dim lineNum As Long + validRowCount = 0 For lineNum = 0 To UBound(lines) If Trim(lines(lineNum)) <> "" Then dataArray = Split(lines(lineNum), ",") @@ -55,9 +57,15 @@ Sub ImportMasterDetailData() MsgBox "CSV line " & (lineNum + 1) & " has " & (UBound(dataArray) + 1) & " columns. Expected 7.", vbExclamation Exit Sub End If + validRowCount = validRowCount + 1 End If Next lineNum + If validRowCount = 0 Then + MsgBox "No valid data in CSV.", vbExclamation + Exit Sub + End If + ' === Clear all data rows before import === lastRow = wsTarget.Cells(wsTarget.Rows.Count, "C").End(xlUp).Row If lastRow >= 7 Then