Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Magenta Ricci   on Nov 02 In MS Office Category.

  
Question Answered By: Funsani Chalthoum    on Nov 02

This helped a lot. Thanks to all who gave me advice on this project.
Here is my first macro, for everyone to enjoy.
=]

Public JumpSize As Integer
'This routine should be programmed to a button on your mouse.
'It makes the active cell jump to the right. The user can modify the
'size of the jump simply by selecting several vertically adjacent cells
'To reset the size of the jump to 1, select 2 horizontally adjacent cells
'The JumpMultiplier can be used to make the jumps bigger without
'the user having to select a large number of vertically adjacent cells.
'by ./mat/.

Sub JumpRight()
Dim x As Integer
Dim y As Integer
Dim JumpMultiplier As Integer

'Count the vertical and horizontal cells selected.
x = Selection.Rows.Count
y = Selection.Columns.Count

'Initialize JumpMultiplier. The active cell will jump JumpSize *
JumpMultiplier
JumpMultiplier = 1

'Set default value for JumpSize.
If JumpSize = 0 Then
JumpSize = x
End If

'If 2 horizontaly adjacent cells are selected, reset JumpSize to 1
If x = 1 And y = 2 Then
JumpSize = 1

'If a single cell is selected, do not change JumpSize
ElseIf x = 1 And y = 1 Then

'If more than one vertically adjacent cells are selected,
'change the jump size accordingly.
ElseIf x > 1 Then
JumpSize = x
End If

'move Active Cell JumpSize * JumpMultiplier columns to the right.
ActiveCell.Offset(0, JumpSize * JumpMultiplier).Activate
'for testing purposes:
'ActiveCell = JumpSize
End Sub

Share: 

 

This Question has 9 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on how to preserve variable value between subroutine calls? Or get search suggestion and latest updates.


Tagged: