Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Selecting a row relative to the position of a button

I'm brand new to macros, so I apologize if this is a particularly dumb
question. I'm copying a hidden row and trying to insert it just below
a button on a spreadsheet. The location of the button will be
variable, so I need the row to be inserted relative to the position of
the button. Here's what I have so far:

Sub Button64_Click()
'
'
ActiveSheet.Unprotect Password:="test"
Rows("9").EntireRow.Hidden = False
Rows("9:9").Select
Selection.Copy
Rows("22:22").Select
Selection.Insert Shift:=xlDown
Rows("9").EntireRow.Hidden = True
ActiveSheet.Protect Password:="test"
End Sub

Instead of 'Rows("22:22").Select', I need to select the row immediately
after the button.

I'm sure there's a much more elegant way to do this, so any suggestions
are very welcome!

Thanks so much!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Selecting a row relative to the position of a button

HH,

The ".TopLeftCell" property is what you are looking for.
The Button should be from the Control Toolbox.
The code should be in the sheet module behind the sheet.
Assumes the button is the height of two rows, so to go
below it the insertion is offset by two rows.
Me refers to the sheet.

Jim Cone
San Francisco, USA
'--------------------------
Private Sub Button64_Click()
Application.ScreenUpdating = False
Me.Unprotect Password:="test"
Rows(9).EntireRow.Hidden = False
Rows(9).Copy
Me.Button64.TopLeftCell.EntireRow.Offset(2, 0).Insert shift:=xlDown
Me.Button64.TopLeftCell.Offset(2, 0).Select
Rows(9).EntireRow.Hidden = True
Me.Protect Password:="test"
Application.ScreenUpdating = True
End Sub
'-------------------------------


"HHall" wrote in message ups.com...
I'm brand new to macros, so I apologize if this is a particularly dumb
question. I'm copying a hidden row and trying to insert it just below
a button on a spreadsheet. The location of the button will be
variable, so I need the row to be inserted relative to the position of
the button. Here's what I have so far:
Sub Button64_Click()'
ActiveSheet.Unprotect Password:="test"
Rows("9").EntireRow.Hidden = False
Rows("9:9").Select
Selection.Copy
Rows("22:22").Select
Selection.Insert Shift:=xlDown
Rows("9").EntireRow.Hidden = True
ActiveSheet.Protect Password:="test"
End Sub

Instead of 'Rows("22:22").Select', I need to select the row immediately
after the button.
I'm sure there's a much more elegant way to do this, so any suggestions
are very welcome!
Thanks so much!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Selecting a row relative to the position of a button

This should work with a button from the Forms tool bar:
Sub Button1_Click()
Dim btnRow As Long

btnRow = Sheet1.Shapes("button 1").BottomRightCell.Row
ActiveSheet.Unprotect Password:="test"
With Rows(9).EntireRow
.Hidden = False
.Copy
End With
Rows(btnRow).Insert Shift:=xlDown
Rows(9).EntireRow.Hidden = True
ActiveSheet.Protect Password:="test"
End Sub

Mike F
"HHall" wrote in message
ups.com...
I'm brand new to macros, so I apologize if this is a particularly dumb
question. I'm copying a hidden row and trying to insert it just below
a button on a spreadsheet. The location of the button will be
variable, so I need the row to be inserted relative to the position of
the button. Here's what I have so far:

Sub Button64_Click()
'
'
ActiveSheet.Unprotect Password:="test"
Rows("9").EntireRow.Hidden = False
Rows("9:9").Select
Selection.Copy
Rows("22:22").Select
Selection.Insert Shift:=xlDown
Rows("9").EntireRow.Hidden = True
ActiveSheet.Protect Password:="test"
End Sub

Instead of 'Rows("22:22").Select', I need to select the row immediately
after the button.

I'm sure there's a much more elegant way to do this, so any suggestions
are very welcome!

Thanks so much!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to macro to relative position jk9533 Excel Discussion (Misc queries) 6 October 15th 07 08:11 PM
Relative position of Employees Bob Davison Excel Worksheet Functions 9 May 8th 07 07:23 PM
Relative Position in VBA Array jgdavis Excel Programming 0 June 23rd 04 03:09 PM
Macro relative to button position wesandem Excel Programming 14 January 26th 04 03:08 AM
relative position in macro pabs[_10_] Excel Programming 4 January 3rd 04 06:25 AM


All times are GMT +1. The time now is 10:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"