Z1 CSV import - validate all rows first, map CSV 1-7 to C-I
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user