LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Modify range variable passed through Function

I wrote a function where, amongst other things, a range is passed through. I
want to allow a range to be passed so that the multiple columns can be
passed, if necessary, and on different sheets. Otherwise, I could just make
the required pass through a column number...but, I want to keep the
flexibility of a passed range.

Once I have this range passed, I loop through each cell in the range,
performing various calculations. Now, if someone passes the range "D:D", my
code loops through all 65000+ cells, skipping most of the For... loop if the
cell.value = "". What I would like to do is figure out the last valid cell
in the passed range, before going through the For... loop, so that I can cut
down the number of looped cells significantly.

I could do something like this, but it seems very messy and only handles one
column. I guess I'm looking for a way to speed up looping through a passed
range, without looping through the entire range. Thanks for any help!

Public Sub test()
Dim rng As Range
Dim rgn2 As Range
Dim str1 As String
Dim str2 As String

Set rng = Range("Sheet1!D:D")

str1 = rng.Worksheet.name & "!"
str2 = rng.Address
str1 = str1 & Left(str2, InStr(1, str2, ":") - 1) & "1:"
str1 = str1 & Range(rng.Worksheet.name & "!" & Mid(str2, InStr(1, str2, ":")
+ 1) & "65536").End(xlUp).Address

Debug.Print str1

End Sub

 
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
Variable passed to database query Vijay Kotian Excel Discussion (Misc queries) 1 August 29th 08 05:00 PM
Excel2000: Reading values from range, passed to function as parameter using an expression Arvi Laanemets Excel Programming 3 April 29th 05 02:34 PM
ClearContents method on a passed range bryan New Users to Excel 2 January 19th 05 08:49 AM
PrintOut macro from ?passed range.addrsess Jabba Excel Programming 1 November 2nd 04 01:53 AM
Translate range name passed as string to a custom function to range addresses! agarwaldvk[_25_] Excel Programming 3 September 7th 04 12:47 PM


All times are GMT +1. The time now is 08:54 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"