cell top of screen

  • Thread starter Thread starter ranswert
  • Start date Start date
I tried that and got the "Appliction-defined or object-defined error"
 
Did you try it with only two Range calls? Try the following (and follow each
step exactly). Go to a blank worksheet and rename it to SheetX so we are
both using the same sheet name (insert a new sheet and rename that if you
don't have an empty worksheet in your current workbook). Go to cell D5 and
name it Cell_D5. Type Cell_X100 into cell D5. Now go to cell X100 and name
it Cell_X100. Enter something into cell X100 so you will recognize it. Now
press the Home key to take you back to cell A1. Okay, that is all the set up
you need. Now, right click the worksheet's tab and select View Code to get
into the VBA editor. Copy/paste the following into this sheet's code
window...

Sub Test()
Dim ycell As Range
With Worksheets("SheetX")
Set ycell = .Range(.Range("Cell_D5"))
Application.Goto ycell, scroll:=True
End With
End Sub

Now execute this subroutine and then go back into your worksheet... the top,
left cell should be X100. If that worked for you, as I think it will have,
then that is what I was trying to convey to you in my last post... it is
what I think you described you wanted to do in your original posting. You
will have to adopt the concept to what you are actually doing in your own
code. You can now delete SheetX so it won't remain in your workbook. By the
way, because we set the worksheet in the With statement, and each Range call
has a "dot" in front of it so as to reference that worksheet, the above
subroutine could have been located anywhere (I just put it on SheetX so it
would be deleted when SheetX was removed from your workbook).

Rick
 
Probably the simplest way is:

Sub cellTotop()
Set x = ActiveCell
Application.Goto x, scroll:=True
End Sub

This way you don't have to worry about named ranges vs variables.
 

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

Back
Top