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)
|
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
|
Dim lineNum As Long
|
||||||
|
validRowCount = 0
|
||||||
For lineNum = 0 To UBound(lines)
|
For lineNum = 0 To UBound(lines)
|
||||||
If Trim(lines(lineNum)) <> "" Then
|
If Trim(lines(lineNum)) <> "" Then
|
||||||
dataArray = Split(lines(lineNum), ",")
|
dataArray = Split(lines(lineNum), ",")
|
||||||
@@ -55,9 +57,15 @@ Sub ImportMasterDetailData()
|
|||||||
MsgBox "CSV line " & (lineNum + 1) & " has " & (UBound(dataArray) + 1) & " columns. Expected 7.", vbExclamation
|
MsgBox "CSV line " & (lineNum + 1) & " has " & (UBound(dataArray) + 1) & " columns. Expected 7.", vbExclamation
|
||||||
Exit Sub
|
Exit Sub
|
||||||
End If
|
End If
|
||||||
|
validRowCount = validRowCount + 1
|
||||||
End If
|
End If
|
||||||
Next lineNum
|
Next lineNum
|
||||||
|
|
||||||
|
If validRowCount = 0 Then
|
||||||
|
MsgBox "No valid data in CSV.", vbExclamation
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
|
||||||
' === Clear all data rows before import ===
|
' === Clear all data rows before import ===
|
||||||
lastRow = wsTarget.Cells(wsTarget.Rows.Count, "C").End(xlUp).Row
|
lastRow = wsTarget.Cells(wsTarget.Rows.Count, "C").End(xlUp).Row
|
||||||
If lastRow >= 7 Then
|
If lastRow >= 7 Then
|
||||||
|
|||||||
Reference in New Issue
Block a user