#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default RANGE QUERY

How can i achieve the following using code
i need the Range 'Fields' to 'shrink' by the first cell being removed after
some code is processed i.e

Dim Fields As Range

Fields = Range("B9,C9,I9,J9")
to
Fields = Range("C9,I9,J9")
to
Fields = Range("I9,J9")
to
Fields= Range("J9")

Cheers for all your help so far








  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default RANGE QUERY

Add the below function

Function GetTrimRange(strRange) As String
GetTrimRange = Mid(strRange, InStr(strRange, ",") + 1)
End Function

strFields = GetTrimRange("B9,C9,I9,J9")
Fields = Range(strFields)

strFields = GetTrimRange(strFields)
Fields = Range(strFields)

If this post helps click Yes
---------------
Jacob Skaria


"sunilpatel" wrote:

How can i achieve the following using code
i need the Range 'Fields' to 'shrink' by the first cell being removed after
some code is processed i.e

Dim Fields As Range

Fields = Range("B9,C9,I9,J9")
to
Fields = Range("C9,I9,J9")
to
Fields = Range("I9,J9")
to
Fields= Range("J9")

Cheers for all your help so far









  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default RANGE QUERY

Even better...Try running this..Function modified to accept range and return
range


Sub Mac()
Dim rngMyRange As Range
Dim rngMyNewRange As Range

Set rngMyRange = Range("A1,A2,A3,A4")
Set rngMyNewRange = GetTrimRange(rngMyRange)

MsgBox rngMyNewRange.Address

End Sub

Function GetTrimRange(rngTemp As Range) As Range
strTrimRange = Mid(rngTemp.Address, InStr(rngTemp.Address, ",") + 1)
Set GetTrimRange = Range(strTrimRange)
End Function


If this post helps click Yes
---------------
Jacob Skaria


"sunilpatel" wrote:

How can i achieve the following using code
i need the Range 'Fields' to 'shrink' by the first cell being removed after
some code is processed i.e

Dim Fields As Range

Fields = Range("B9,C9,I9,J9")
to
Fields = Range("C9,I9,J9")
to
Fields = Range("I9,J9")
to
Fields= Range("J9")

Cheers for all your help so far









  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default RANGE QUERY

Put the address in a String variable and then manipulate that.

Addr = "B9,C9,I9,J9"
MsgBox Range(Addr).Address
Addr = Left(Addr, InStrRev(Addr, ",") - 1)
MsgBox Range(Addr).Address
Addr = Left(Addr, InStrRev(Addr, ",") - 1)
MsgBox Range(Addr).Address
Addr = Left(Addr, InStrRev(Addr, ",") - 1)
MsgBox Range(Addr).Address

where I have used the MsgBox statements as a stand-in for your processing
code.

--
Rick (MVP - Excel)


"sunilpatel" wrote in message
...
How can i achieve the following using code
i need the Range 'Fields' to 'shrink' by the first cell being removed
after some code is processed i.e

Dim Fields As Range

Fields = Range("B9,C9,I9,J9")
to
Fields = Range("C9,I9,J9")
to
Fields = Range("I9,J9")
to
Fields= Range("J9")

Cheers for all your help so far









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
VBA: Edit Web Query with Range(B24).Value CM4@FL[_2_] Excel Programming 1 April 13th 09 08:15 PM
Range statemeny query Graham H Excel Programming 5 July 3rd 08 01:24 PM
Using range names in SQL query Rey[_3_] Excel Programming 3 January 29th 08 04:26 PM
Used range and SQL query Laurent[_2_] Excel Programming 5 October 29th 07 06:09 AM
Searching a range with MS Query dsb Excel Worksheet Functions 3 November 1st 06 11:04 PM


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