itchyII
MIS
- Apr 10, 2001
- 167
Hi Everyone,
I am experiencing something very frustrating. I am working in Excel 2000 and I have this really volatile workbook with a couple of input sheets and then lots of calculations and formulas populating ranges on other sheets that produce all kinds of graphs. In one of the spreadsheets, there is a column that contains the column letters of another worksheet (it refers to questions on the other worksheet, and the answers to the questions are in the adjacent column to the right of the question). I have a function that I created that reads this column letter and is supposed to derive the letter of the column next to the one being refered to in the text of the column(basically, I want to determine the answer column letter). Example: text in cell = C, the function should output "D" to indicate the next column over. I know that the simple answer would be to store the letters of the answer column instead of the question column but I can't do this for other reasons. Anyhow, the following is the code that I am using to get the letter that I am looking for.
The problem is that it doesn't always work! Sometimes it does and sometimes it outputs a column letter completely wrong. For example, wks.Range("J" & x + 1).Value = C and the function is outputting 'E'. For debugging purposes, I even tried
col = Range(wks.Range("C1").Offset(0, 1).Address
and it still output 'E'. This function gave me similar problems yesterday, and after debugging for about 45 minutes, I gave up and closed the workbook. When I re-opened it. It was working fine again. I tried this this time, but its not working. The code seems to be ok. Do any of you think that there could be a memory leak in my code somewhere that's causing these unexpected results?
ItchyII
I am experiencing something very frustrating. I am working in Excel 2000 and I have this really volatile workbook with a couple of input sheets and then lots of calculations and formulas populating ranges on other sheets that produce all kinds of graphs. In one of the spreadsheets, there is a column that contains the column letters of another worksheet (it refers to questions on the other worksheet, and the answers to the questions are in the adjacent column to the right of the question). I have a function that I created that reads this column letter and is supposed to derive the letter of the column next to the one being refered to in the text of the column(basically, I want to determine the answer column letter). Example: text in cell = C, the function should output "D" to indicate the next column over. I know that the simple answer would be to store the letters of the answer column instead of the question column but I can't do this for other reasons. Anyhow, the following is the code that I am using to get the letter that I am looking for.
Code:
Function findResponseCol(quest As String) As String
Dim wks As Worksheet
Dim rows As Integer
Dim col As String
Dim x As Integer
Set wks = Worksheets("Questions")
'get number of rows in worksheet
rows = findNumRows(wks, "E", 1, "Total")
'loop through rows on the 'Questions' worksheet
For x = 1 To rows
'find the matching question
If wks.Range("E" & x + 1).Value = quest Then
'goto column that contains the column letter and use offset
'to get the next column letter
col = Range(wks.Range("J" & x + 1).Value & "1").Offset(0, 1).Address
findResponseCol = mid(col, 2, Len(col) - 3)
Exit For
End If
Next x
Set wks = Nothing
End Function
The problem is that it doesn't always work! Sometimes it does and sometimes it outputs a column letter completely wrong. For example, wks.Range("J" & x + 1).Value = C and the function is outputting 'E'. For debugging purposes, I even tried
col = Range(wks.Range("C1").Offset(0, 1).Address
and it still output 'E'. This function gave me similar problems yesterday, and after debugging for about 45 minutes, I gave up and closed the workbook. When I re-opened it. It was working fine again. I tried this this time, but its not working. The code seems to be ok. Do any of you think that there could be a memory leak in my code somewhere that's causing these unexpected results?
ItchyII