PC Review


Reply
Thread Tools Rate Thread

Auto Positioning the Cursor before Executing Code

 
 
Racqetsports@gmail.com
Guest
Posts: n/a
 
      16th Oct 2007
Hi There!
I've gleaned some code that copies 2 rows and inserts them below the
2nd row (2 rows below the active). However, this only works right if
a user has clicked on an appropriate row. If a user has clicked
somewhere else, like in the heading section, how can the cursor first
be positioned in column A on the last row with data in columns A and
B?

Thanks!
Tracy

 
Reply With Quote
 
 
 
 
JW
Guest
Posts: n/a
 
      16th Oct 2007

Racqetspo...@gmail.com wrote:
> Hi There!
> I've gleaned some code that copies 2 rows and inserts them below the
> 2nd row (2 rows below the active). However, this only works right if
> a user has clicked on an appropriate row. If a user has clicked
> somewhere else, like in the heading section, how can the cursor first
> be positioned in column A on the last row with data in columns A and
> B?
>
> Thanks!
> Tracy


As per your information, this will select the last cell in column A
where both column A and column B have data. That being said, if the
last row containing data in column A is 28 and the last row containing
data in column B is 15, the cell A15 will be selected, because you
said the last row where A dna B contain data. Tweak as needed.

Sub selectLast()
Dim aRow As Long, bRow As Long, selRow As Long
aRow = Cells(Rows.Count, 1).End(xlUp).Row
bRow = Cells(Rows.Count, 2).End(xlUp).Row
selRow = WorksheetFunction.Min(aRow, bRow)
Cells(selRow, 1).Select
End Sub

 
Reply With Quote
 
JW
Guest
Posts: n/a
 
      16th Oct 2007
Also, keep in mind that a selection doesn't have to be made to
accomplish this. You just need to identify the last row and proceed
acordingly.
As per your information, this will select the last cell in column A
where both column A and column B have data. That being said, if the
last row containing data in column A is 28 and the last row containing
data in column B is 15, the cell A15 will be selected, because you
said the last row where A dna B contain data. Tweak as needed. This
is assuming that you already have something placed on your clipboard.

Sub withoutSelectLast()
Dim aRow As Long, bRow As Long, selRow As Long
aRow = Cells(Rows.Count, 1).End(xlUp).Row
bRow = Cells(Rows.Count, 2).End(xlUp).Row
selRow = WorksheetFunction.Min(aRow, bRow)
Cells(selRow, 1).Offset(2, 0).Insert Shift:=xlDown
End Sub

Racqetspo...@gmail.com wrote:
> Hi There!
> I've gleaned some code that copies 2 rows and inserts them below the
> 2nd row (2 rows below the active). However, this only works right if
> a user has clicked on an appropriate row. If a user has clicked
> somewhere else, like in the heading section, how can the cursor first
> be positioned in column A on the last row with data in columns A and
> B?
>
> Thanks!
> Tracy


 
Reply With Quote
 
Racqetsports@gmail.com
Guest
Posts: n/a
 
      16th Oct 2007
Very good; thanks!

 
Reply With Quote
 
Racqetsports@gmail.com
Guest
Posts: n/a
 
      16th Oct 2007
Oops--one more thing. This needs to be restricted to row 14 or
above. Meaning, if a user has clicked somewhere above row 14, then do
your code. If the user has clicked on row 15 or below, then don't do
your code.
:-)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cursor positioning =?Utf-8?B?bXVsbGlnYm8=?= Microsoft Excel Misc 6 6th Nov 2006 05:26 AM
Positioning Cursor =?Utf-8?B?VWxyaWNoMTk0Nw==?= Microsoft Access VBA Modules 5 14th Apr 2006 03:58 PM
positioning of cursor Brian Garnett Windows XP Accessibility 1 8th Apr 2004 02:18 PM
Code for positioning cursor in many sheets Sandy Microsoft Excel Programming 3 6th Sep 2003 09:22 PM
cursor positioning john Microsoft Frontpage 1 20th Jul 2003 02:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:00 AM.