Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15107

find the elements that are not in both objects vb.net

$
0
0
Hello guys, im trying to loop over two collumns in two worksheets if an element is in both columns i sort it in a datagrid otherwise, if it's only in one (in the worksheet ws1) and it doesn't existe in the othe column i also wanna add it but don't know how, i will post part of my code maybe it will explain more.
Code:

Dim ws1 as excel.worksheet
Dim ws2 as excel.worksheet
 ws1 = xlApp.Workbooks.Open(TextBox1.Text).Worksheets(ComboBox1.SelectedItem)
 ws2 = xlApp.Workbooks.Open(TextBox2.Text).Worksheets(ComboBox2.SelectedItem)

Dim findme1 As Excel.Range = ws1.Range("A4:A" & Range1.Rows.Count)
Dim findme2 As Excel.Range = ws2.Range("F5:F" & Range2.Rows.Count)
Dim MyArray As Object(,) = CType(findme1.Value, Object(,))
Dim MyArrayy As Object(,) = CType(findme2.Value, Object(,))


For n = 1 To MyArray.Length
          For m = 1 To MyArrayy.Length
                If MyArray(n, 1) = MyArrayy(m, 1) Then
                                    Form2.DataGridView1.Rows.Add(MyArray(n, 1), MyArrayy(m, 1), "Not OK")
                End If

          Next
Next

i wanna add to the datagridview the ones that are just in findme1 and do not exist in findme2 thank you so much in advanced

Viewing all articles
Browse latest Browse all 15107

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>