Guys I need your help again

I use this code to copy values from excel spreadsheet to datagrid.

Try
                's = Clipboard.GetText()
                Dim tArr() As String
                Dim arT() As String
                Dim i, ii As Integer
                Dim c, cc, r As Integer

                tArr = Clipboard.GetText().Split(Environment.NewLine)
                r = Form1.DataGridView1.SelectedCells(0).RowIndex
                c = Form1.DataGridView1.SelectedCells(0).ColumnIndex
                For i = 0 To tArr.Length - 1
                    If tArr(i) <> "" Then
                        arT = tArr(i).Split(vbTab)
                        cc = c
                        For ii = 0 To arT.Length - 2
                            If cc > Form1.DataGridView1.ColumnCount - 1 Then Exit For
                            If r > Form1.DataGridView1.Rows.Count - 1 Then Exit Sub
                            With Form1.DataGridView1.Item(cc, r)
                                .Value = arT(ii).TrimStart
                            End With
                            cc = cc + 1
                        Next

                        r = r + 1

                    End If

                Next

            Catch ex As Exception

                MsgBox("Please redo Copy and Click on cell")

            End Try

It works fine but is it possible for some certain cells in datagrid not to be pasted with value? Example:

In datagrid Columns A, B, C, D, E are shown while in excel spreadsheet there are columns A, B, D, E.

If I copy the values from excel the value of columns D and E will be pasted in columns C and D in datagrid?

Wouldn't changing cc=cc+1on line 21 into cc=cc+iif(cc=1,2,1) do what you want?

In a zero based logic you will put your valuese in columns 0,1,3 and 4.

If you'd allow me, I'd suggest that you be slightly less cryptic in the way you name your variables. There's no extra charge for using clear variable names :)

Hope this helps and good luck.

Thanks for the suggestion. Actually I got this code from a blog. Anyway I solved my problem, my boss said I can change their template. Thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.