Note that there are some explanatory texts on larger screens.

plurals
  1. POCan not access a cell in Excel using VBA script
    text
    copied!<p>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:</p> <pre><code>s_WS_string = Workbooks(s_WS_Filename).Sheets(s_WS_SheetName).Range(s_WS_col &amp; s_WS_row).Value </code></pre> <p>Where <code>s_WS_col</code> and <code>s_WS_row</code> are defined strings in the VBA script. This command successfully retrieves data. However, </p> <pre><code>OURS_string = Workbooks("OURS.xlsx").Sheets("Sheet1").Range(s_OURS_col &amp; s_OURS_row).Value </code></pre> <p>Does not. <code>s_OURS_col</code> and <code>s_OURS_row</code> are both strings as well. <code>WS</code> stands for worksheet, which is the variable worksheet being compared against the static <code>OURS.xlsx</code> sheet. </p> <p>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. </p> <p>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 <code>OURS.xlsx</code>, even when it access a cell that contains the exact same data, it will remain empty, and thus be considered to not match. </p> <p>Has anyone else seen this problem? </p> <p>Edit 1: Clarified some problems. </p> <p>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. </p> <p>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. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload