Select statement failing

D

DesertCyclist

Can anyone please tell me what might lead Excel to ignore these statements:

Worksheets(“Logâ€).Select
Range(“E4â€).Select
ActiveCell.Offset(1,0).Select

There is a “Log†worksheet, there is a cell E4 in it, and there is a cell
below it. These statements are so basic. I’ve never encountered a situation
in which Excel would ignore them, so I am at a loss to know where to even
start looking.

Here are some hopefully-relevant facts:

These statements are in a function in a module.
The function is called from a cell.
The function is executing (it hits a breakpoint).
The cell containing the function call is not in the range of cells that the
function takes as parameters (changes to which cause the function to execute).
The range of cells through which it is looping is the same as the range of
cells that the function takes as parameters (changes to which cause the
function to execute).

Here is the function:

Public Function CurrentWeight() As Single

Dim CurrentSheetName As String

CurrentSheetName = ActiveSheet.Name

Worksheets("Log").Select
Range("E4").Select
Do

If InStr("Sun Mon Tue Wed Thu Fri Sat", ActiveCell.Offset(0,
-2).Value) > 0 And ActiveCell.Value <> "" Then
CurrentWeight = ActiveCell.Value
End If

Do
ActiveCell.Offset(1, 0).Select
Loop Until InStr("Sun Mon Tue Wed Thu Fri Sat", ActiveCell.Offset(0,
-2).Value) > 0 And ActiveCell.Value = ""

Loop

Worksheets(CurrentSheetName).Select

End Function


Any help would be appreciated.

Thank you
 
J

JLGWhiz

Your outer loop needs a condition to stop it. Right now it is endless.
Do until ? loop until ?
 
T

Tim Williams

A function called from a worksheet cell formula can't change the Excel
environment (eg. format cells etc).
Presumably that also extends to selecting sheets/cells.

However, your formula doesn't need any of those Select's.


Tim
 
D

DesertCyclist

The function is only reading values and not changing anything. It doesn't
need the selets? How so?
 
D

DesertCyclist

Oh, I think I see what you mean. Instead of the selects, I can just "examine"
the contents of the cells. That sounds promising. I'll try that. Thank you.
 
B

BIG_j

BTW,

You need to make the sheet "active" first. So you would do...

Worksheets(“Logâ€).Activate
Worksheets(“Logâ€).Select

or

ActiveSheet.Range(“E4â€).Select

ActiveCell.Offset(1,0).Select
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top