Hi Guys,
I seem to have gotten myself into a filtering conundrum.
I have two DataGridView tables that are not bound to anything in a Visual Basic 2026 app that I am playing with.
DataGridView1 is located on form1 and is an 18 row by 15 column table
DataGridView2 is on form DB and is a 216 row by 27 column table
DataGridView1 Column 9 has unique strings and is the what I need to use to search DataGridView2
The filter is date dependent
DataGridView2 Column 3 and Column 10 have the 18 unique strings randomly populated throughout the two columns.
The rows do not have duplicated strings
DataGridView2 Column 6 has dates that span the entire year.
GV.CurrentDate is just the system date.now value
I have been trying to search DataGridView2 for the first instance of a date in column 6 that is greater than today
and then check to see if column 18 is empty.
Then I need to look ahead row by row for 22 rows and do the following on the first match it finds for each of the 18 rows in DataGridView1
If Column 18 is empty then if DataGridView1 column 9 = DataGridView2 column3 or DataGridView2 column10 assign DataGridView2 column 10 value to DataGridView1 column 15 else assign DataGridView2 column 3 to DataGridView1 column 15
If column 18 is not empty and DataGridView1 column 9 = either DataGridView2 column 3 or column 10 then get the value from DataGridView2 column 26 or column 27 respectively and assign it to DataGridView1 column 15
This needs to be done for all 18 rows in DataGridView1
All the columns do have headers but I haven't been able to figure out how to use them(like Excel)
Here is the code that I have been fumbling with for a couple of weeks now.
I am hoping that someone will be able to point out the errors in my ways so that I can get this to work.Code:Public Sub FindNext() Dim rowsahead As Integer Form1.DataGridView1.ReadOnly = False For datarows = 0 To 199 If DB.DataGridView1.Rows(datarows).Cells(6).Value > GV.CurrentDate Then For list = 0 To 17 For rowsahead = 1 To 22 If DB.DataGridView1.Rows(datarows).Cells(18).Value > Nothing Then If Form1.DataGridView1.Rows(list).Cells(9).Value = DB.DataGridView1.Rows(datarows + rowsahead).Cells(10).Value OrElse Form1.DataGridView1.Rows(list).Cells(9).Value = DB.DataGridView1.Rows(datarows + rowsahead).Cells(3).Value Then If Form1.DataGridView1.Rows(list).Cells(9).Value = DB.DataGridView1.Rows(datarows + rowsahead).Cells(10).Value Then Form1.DataGridView1.Rows(list).Cells(15).Value = DB.DataGridView1.Rows(datarows + rowsahead).Cells(27).Value Else Form1.DataGridView1.Rows(list).Cells(15).Value = DB.DataGridView1.Rows(datarows + rowsahead).Cells(26).Value End If Exit For Else End If Else If Form1.DataGridView1.Rows(list).Cells(9).Value = DB.DataGridView1.Rows(datarows).Cells(3).Value Then Form1.DataGridView1.Rows(list).Cells(15).Value = DB.DataGridView1.Rows(datarows).Cells(10).Value If Form1.DataGridView1.Rows(list).Cells(9).Value = DB.DataGridView1.Rows(datarows).Cells(10).Value Then Form1.DataGridView1.Rows(list).Cells(15).Value = DB.DataGridView1.Rows(datarows).Cells(3).Value Exit For End If Next Next End If If DB.DataGridView1.Rows(datarows).Cells(6).Value > GV.CurrentDate Then Exit For Next End Sub
Many Thanks
Regards
Antony




Reply With Quote
