Good Morning,
I have been searching for hours for the answer to this question. I have ZERO experience with VBA, but am trying to make an idea come to life. I have an excel sheet which pulls a bunch of data from an Access Query. I want the user of this spreadsheet, specifically tab/worksheet titled "Download Data" to which the query is linked, to be able to enter a value in cell B2 and then click the "Run Query" button to filter the data. I want the macro behind that button to search every cell in column A which contains data and compare it to the value which was entered in cell B2. When the cell in column A does not equal the value which was placed in cell B2, I want it to delete that entire Row. I then want it to search for and delete duplicate values in Column E. So far here is what I have come up with in my research for the first step of this process:
Sub Button1_Click()
For i = .Range("A" & Rows.Count).End(x1Up).Row To 3 Step -1
If Range("A" & i).Value <> Cells(1, 2) Then Rows(i).Delete shift:=x1Up
Next i
End Sub
The data in Red is highlighted in my VBA editor, so I'm assuming my error is there. Like I said, I no experience so I don't know what any of this stuff means, or where to input data which pertains to my spreadsheet specifically vs generic information that applies to all spreadsheets. My data starts in row 3. Row 1 contains my button and the cell which will be used to input the filter data. Row 2 is just column headings. As of right now, there are over 500,000 rows with information, but this fluctuates so I need an open-ended range of rows to check, starting with row 3.
Hopefully this all makes sense. Please feel free to roll your eyes at me and call me a moron, I'm sure there are many people who will be able to write out this code in a matter of seconds but it is just flying right over my head. Thank you so much for your help!
I have been searching for hours for the answer to this question. I have ZERO experience with VBA, but am trying to make an idea come to life. I have an excel sheet which pulls a bunch of data from an Access Query. I want the user of this spreadsheet, specifically tab/worksheet titled "Download Data" to which the query is linked, to be able to enter a value in cell B2 and then click the "Run Query" button to filter the data. I want the macro behind that button to search every cell in column A which contains data and compare it to the value which was entered in cell B2. When the cell in column A does not equal the value which was placed in cell B2, I want it to delete that entire Row. I then want it to search for and delete duplicate values in Column E. So far here is what I have come up with in my research for the first step of this process:
Sub Button1_Click()
For i = .Range("A" & Rows.Count).End(x1Up).Row To 3 Step -1
If Range("A" & i).Value <> Cells(1, 2) Then Rows(i).Delete shift:=x1Up
Next i
End Sub
The data in Red is highlighted in my VBA editor, so I'm assuming my error is there. Like I said, I no experience so I don't know what any of this stuff means, or where to input data which pertains to my spreadsheet specifically vs generic information that applies to all spreadsheets. My data starts in row 3. Row 1 contains my button and the cell which will be used to input the filter data. Row 2 is just column headings. As of right now, there are over 500,000 rows with information, but this fluctuates so I need an open-ended range of rows to check, starting with row 3.
Hopefully this all makes sense. Please feel free to roll your eyes at me and call me a moron, I'm sure there are many people who will be able to write out this code in a matter of seconds but it is just flying right over my head. Thank you so much for your help!