Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to select & activate cells

Status
Not open for further replies.

JTBorton

Technical User
Jun 9, 2008
345
DE
A procedure analyzes data and builds a presentation out of it. If the data has not been properly processed (by other preceding methods in the excel sheet), the user should be redirected to complete that portion first. I am having trouble getting excel to redirect the user to the data which needs to be pre-processed. I want it to jump to the correct worksheet and highlight the row or cell. However it will not let me do this.

The code breaks out of a for loop to handle this error. The for loop has this basic skeletal structure:
Code:
With [worksheet]
    For I = 1 To EndofData
        If Not .Cells(I, 4).Comment Is Nothing Then
            [Analyze Data]
        Else
            [Handle Error & Redirect]
        End If
    Next I
End With

Here is the offending code:
Run-time error '1004':
Application-defined or object defined error


Code:
Redirect_To_PEP_Analysis:
With Worksheets("Master") [This worksheet is different from the loop above]
    I = 3
    Do
        I = I + 1
        If CLng(.Cells(I, 1)) = lngUPE_Num Then '(The cell matches the ID number)
                [COLOR=green]':::::::::::::::::::::::::::      FLAG FOR DEBUG      :::::::::::::::::::::::::::[/color]
            [highlight].Range(.Rows(I)).Select 'Error Here[/highlight]
            .Activate
            Exit Do
        ElseIf .Cells(I, 1) = "" Then
            Exit Do
        End If
    Loop
End With
GoTo Proc_Exit
                    
Proc_Exit:
Set wkshtPEP = Nothing
Exit Sub

I have tried using other methods and get the following errors:
Run-time error '1004': Select method of Range class failed
.Rows(I).Select

Run-time error '1004': Select method of Range class failed
.Cells(I, 1).Select

Run-time error '1004': Method 'Range' of object '_Global' failed
Range(.Cells(I, 1)).Select

Run-time error '1004': Application-defined or object defined error
.Range(.Cells(I, 1)).Select

Anyone know why it won't let me select the cell / row?

-JTBorton
Well, You can try banging your head against the wall, but you just end up with lost-time injuries and damaged equipment. [M. Passman]
 


Hi,
Code:
            .Activate
            .Range(.Rows(I)).Select 'Error Here


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Oh, well that was simple. Thanks Skip. I had to remove the .Range() part to get it to work. It works with

Code:
.Activate
.Rows(I).Select

-JTBorton
Well, You can try banging your head against the wall, but you just end up with lost-time injuries and damaged equipment. [M. Passman]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top