Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 238
Default Current position on worksheet

How can I remain in my current position on worksheet? My macro always
drags me to row 1 when it pastes to a cell.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Current position on worksheet

Post your code

"Fan924" wrote:

How can I remain in my current position on worksheet? My macro always
drags me to row 1 when it pastes to a cell.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Current position on worksheet

How can I remain in my current position on worksheet? My macro always
drags me to row 1 when it pastes to a cell.


Your code presumably involves selecting a range in row 1. Selecting ranges
is rarely necessary in macros. Please post your code. Did you generate it
with the recorder?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 238
Default Current position on worksheet

Your code presumably involves selecting a range in row 1. Selecting ranges
is rarely necessary in macros.


Is there another way to do it without selecting a range?

Sub CheckSum_xx()
Dim r As Range, c As Range
Dim Checksum As Variant
Checksum = 0
Range("E1").Value = "Working"
Range("C2:C8193").Select 'select cells to export
For Each r In Selection.Rows
For Each c In r.Cells
Checksum = Checksum + Val("&h" & UCase(c.Text)) 'hex to
decimal, then sum
Next c
Next r
Range("E1").Value = Right(Hex(Checksum), 4)
End Sub
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Current position on worksheet

Try this

Sub CheckSum_xx()
Dim r As Range, c As Range, MyRange as Range
Dim Checksum As Variant
Checksum = 0
Range("E1").Value = "Working"
Set MyRange = Range("C2:C8193") 'select cells to export
For Each r In MyRange
For Each c In r.Cells
Checksum = Checksum + Val("&h" & UCase(c.Text)) 'hex to
decimal, then sum
Next c
Next r
Range("E1").Value = Right(Hex(Checksum), 4)
End Sub

Mike

"Fan924" wrote:

Your code presumably involves selecting a range in row 1. Selecting ranges
is rarely necessary in macros.


Is there another way to do it without selecting a range?

Sub CheckSum_xx()
Dim r As Range, c As Range
Dim Checksum As Variant
Checksum = 0
Range("E1").Value = "Working"
Range("C2:C8193").Select 'select cells to export
For Each r In Selection.Rows
For Each c In r.Cells
Checksum = Checksum + Val("&h" & UCase(c.Text)) 'hex to
decimal, then sum
Next c
Next r
Range("E1").Value = Right(Hex(Checksum), 4)
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Current position on worksheet

Whenever you see code constructed like this...

Range("A1").Select
Selection.<whatever

you can almost always do this instead...

Range("A1").<whatever

In your particular case, you have this...

Range("C2:C8193").Select 'select cells to export
For Each r In Selection.Rows

which, using the above concept, can be reduced to this...

For Each r In Range("C2:C8193").Rows

Notice, all I have done is replace Selection with the range you Select(ed)
in the previous statement and eliminate the process of doing any
Select(ion)s. Stated another way, the Selection produced from
Range(...).Select is a range and, of course, Range(...) is a range... and,
in fact, they are the same range, so it doesn't matter which one you use.
The added benefit of not selecting ranges first is your active cell does not
change.

--
Rick (MVP - Excel)


"Fan924" wrote in message
...
Your code presumably involves selecting a range in row 1. Selecting
ranges
is rarely necessary in macros.


Is there another way to do it without selecting a range?

Sub CheckSum_xx()
Dim r As Range, c As Range
Dim Checksum As Variant
Checksum = 0
Range("E1").Value = "Working"
Range("C2:C8193").Select 'select cells to export
For Each r In Selection.Rows
For Each c In r.Cells
Checksum = Checksum + Val("&h" & UCase(c.Text)) 'hex to
decimal, then sum
Next c
Next r
Range("E1").Value = Right(Hex(Checksum), 4)
End Sub


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 238
Default Current position on worksheet

Thanks, works great.
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 get the current cell position in VBA (eq. Row(), col() in F Johan2000 Excel Programming 3 October 6th 10 12:54 AM
How to determine the current position of an open .xls file? Andrew Excel Programming 3 March 20th 07 10:09 PM
How do you set cursor position at current date in macro? Tom Robertson Excel Worksheet Functions 1 May 28th 06 03:50 PM
Current cell position AJPendragon Excel Worksheet Functions 1 February 3rd 06 04:28 PM
how do I get the current cursor position in a spreedsheet Paul J Excel Programming 4 October 1st 04 01:11 AM


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

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

About Us

"It's about Microsoft Excel"