Hi Zelrick,
I just thought that the data that you had provided is in a standard form that consists of 5 digits numerical number. Yes of course an error would occur if there's a blank or the cell length is less than the specified length, because of its calculation to determine the location of the character. But by using a conditional statement, we can do it this way:
Dim cell1, cell3, col1, col2, col3, col4 As String
For Each row As DataRow In dts.Tables("[Sheet1$]").Rows
cell1 = row(0).ToString()
cell3 = row(2).ToString()
col1 = ""
col2 = ""
col3 = ""
col4 = ""
If cell1.Length = 5 Then
col1 = cell1.Substring(0, cell1.Length - 3)
col2 = cell1.Substring(2, cell1.Length - 2)
End If
If cell3.Length = 5 Then
col3 = cell3.Substring(0, cell3.Length - 4)
col4 = cell3.Substring(1, cell3.Length - 2)
End If
DataGridView1.Rows.Add(col1, col2, col3, col4)
Next
The only problem with this code if the cell length is less than or more than 5. But I think it is another problem and out of scope for this discussion that needs for creation to a new thread, so that others can help and contribute.
Thanks,
Hardz