Share via

Using Visual Basic, how do I move the cursor a number of cells specified by a number entered into another cell?

Anonymous
2012-10-30T15:14:35+00:00

I have manually entered a number, let's say 31, into a cell (A1).  I've written code to move the cursor to the top of a column in a table.  I now want to be able to move the cursor down the number of rows specified in cell A1, in this case 31 rows.  Can someone show me how to do this?

Thanks!!!

Sid

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-10-30T21:00:15+00:00

 Now, what is the Visual Basic equivalent of hitting the Escape key?  My code copies info from one cell to another.  After the code runs, I note that the copied cell still has the blinking border.  I need to hit the escape key to stop the blinking.

 

Also, what causes the first solution you suggested to be error prone? 

 

Thanks again . . . you're very kind to help.

 

Sid

Hi,

VBA equivalent is

Application.cutcopymode=false

Selecting things in VBA is generally considered to be a bad idea and is almost never necessary because whatever you want to do in  ActiveCell.Offset(Range("A1")).Select can almost certainly be done without selection. Why is it error prone? Well the activecell can be any cell and possibly not the one you expect it to be when you run the code so when you offset from it there will be a day; one day, when you end up in a cell you didn't expect to be in.

Was this answer helpful?

0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-10-30T21:14:45+00:00

    Thanks Mike.  Worked beautifully!

    I wish I knew Visual Basic well.  It seems so complicated.  Problem is, I don't use it enough.

    Thanks for helping those of us in this situation out!

    Sid

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-10-30T19:32:14+00:00

    Thanks Andreas . . . this works great!  Now, what is the Visual Basic equivalent of hitting the Escape key?  My code copies info from one cell to another.  After the code runs, I note that the copied cell still has the blinking border.  I need to hit the escape key to stop the blinking.

    Also, what causes the first solution you suggested to be error prone? 

    Thanks again . . . you're very kind to help.

    Sid

    Was this answer helpful?

    0 comments No comments
  3. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2012-10-30T16:49:22+00:00

    I have manually entered a number, let's say 31, into a cell (A1).  I've written code to move the cursor to the top of a column in a table.  I now want to be able to move the cursor down the number of rows specified in cell A1, in this case 31 rows. 

      ActiveCell.Offset(Range("A1")).Select

    But please please NEVER NEVER NEVER!! use that in your code.

    Your macro will be slow and error prone. Please read the answer in this thread about that:

    http://answers.microsoft.com/en-us/office/forum/office\_2003-customize/putting-text-string-into-text-box-getting-error/f6840b15-5fff-41dd-96d0-51737b179ff6

    Post your existing macro and explain what you want to achieve. I'm sure that we can do the same much faster, easier and in a safe way!

    Andreas.

    Was this answer helpful?

    0 comments No comments