I'm trying to write some VBA code that will tell me if a row containing exact data exists.
The table (Table1) is formatted as a table with headers, and has 20 columns; the first three columns are what I am concerned with right now.
- Some projects will have multiple associated sites
- Some sites are associated with multiple projects
- Some sites will have multiple pieces of equipment
- The same equipment ID may be used in multiple sites
- Each row will contain only one Project Code, Site, and Equipment ID
The data in this table will be updated from multiple other tables (example shown below; Table name = Project Code; Headers = Sites; Data = Equipment ID) upon a button click, which I am currently working on. I need the VBA code to be able to check whether or not a row for XY_MDF SLO 12C33 exists, and if not, paste the info into the next available row.
I figured out how to check this in-line with hard coded values, which I'll replace as variables in my VBA code:
=IF((Table1[@[Project Code]]="XY_MDF")*(Table1[@Site]="SLO")*(Table1[@[Equipment ID]]="12C33"),"It's a match!", "Nope")
But I'm not sure how to translate this to VBA and get it to check each row to look for a matching row. I don't need to know which row it's in - just whether or not it exists.
Would using the row/column numbers instead of the header names for Table1 make it any easier?
Any guidance on how to approach this would be greatly appreciated!
The table (Table1) is formatted as a table with headers, and has 20 columns; the first three columns are what I am concerned with right now.
- Some projects will have multiple associated sites
- Some sites are associated with multiple projects
- Some sites will have multiple pieces of equipment
- The same equipment ID may be used in multiple sites
- Each row will contain only one Project Code, Site, and Equipment ID
Project Code | Site | Equipment ID |
XY_ADT | QRT | 25A1 |
XY_ADT | AMZ | 25A7 |
XY_MDF | SLO | 12C11 |
XY_CHG | QRT | 60A2 |
XY_MDF | SLO | 12C12 |
The data in this table will be updated from multiple other tables (example shown below; Table name = Project Code; Headers = Sites; Data = Equipment ID) upon a button click, which I am currently working on. I need the VBA code to be able to check whether or not a row for XY_MDF SLO 12C33 exists, and if not, paste the info into the next available row.
I figured out how to check this in-line with hard coded values, which I'll replace as variables in my VBA code:
=IF((Table1[@[Project Code]]="XY_MDF")*(Table1[@Site]="SLO")*(Table1[@[Equipment ID]]="12C33"),"It's a match!", "Nope")
But I'm not sure how to translate this to VBA and get it to check each row to look for a matching row. I don't need to know which row it's in - just whether or not it exists.
Would using the row/column numbers instead of the header names for Table1 make it any easier?
Any guidance on how to approach this would be greatly appreciated!