I have a script that is trying to compare specific data based on a tag number in the first column of an Excel spreadsheet in two different workbooks. When I am trying to access the first workbook, it works great, and I can access the data in the cell properly, with the following command:
s_WS_string = Workbooks(s_WS_Filename).Sheets(s_WS_SheetName).Range(s_WS_col & s_WS_row).Value
Where s_WS_col and s_WS_row are defined strings in the VBA script. This command successfully retrieves data. However,
OURS_string = Workbooks("OURS.xlsx").Sheets("Sheet1").Range(s_OURS_col & s_OURS_row).Value
Does not. s_OURS_col and s_OURS_row are both strings as well. WS stands for worksheet, which is the variable worksheet being compared against the static OURS.xlsx sheet.
They are both the exact same command, being passed the exact same type of parameters, and yet one retrieves data from the cell, while the other does not. I’m in the process of replicating it in another environment for upload if it comes down to that.
The two strings are meant to be compared to each other, and if they dont match, to concatenate and output in a replicated worksheet. Based on my output, and my own debugging, I have found that it will find the value on the first spreadsheet, but on the static spreadsheet OURS.xlsx, even when it access a cell that contains the exact same data, it will remain empty, and thus be considered to not match.
Has anyone else seen this problem?
Edit 1: Clarified some problems.
Edit 2: I understand that both workbooks must be opened in order to access them in this manner, and I assure you both are opened during the running of the script.
Edit 3: I have stepped through the script up to the point where it is passing the arguments to access the values. I have checked the values in both of the cells being passed, and they do match, but one is not being pulled from the workbook properly.
There must be something wrong with at least one of your variables. I recreated your case with 2 workbooks, Book1 and Book2, and added a value in cell A1 of Sheet1 in each. The code runs fine.
Step into your code (F8) and check the values of the variables and make sure they are pointing to the correct objects.