PC Review


Reply
Thread Tools Rate Thread

Contiguous Ranges and 255 Char Limit Constraint

 
 
ExcelMonkey
Guest
Posts: n/a
 
      25th Nov 2008
I know I can pass all the contiguous ranges of cells with formulas as follows
below. However this suffers from the 255 char limit. That is, if the range
is greater than 255 then the cell address that is passed to the ContRange
variable will be truncated. How do you get around this?

Sub test2()
Dim sht As Worksheet
Dim ContRange As String

For Each sht In ThisWorkbook.Worksheets
Set rng1 = sht.Range("a1:iv65536").Cells.SpecialCells(xlFormulas)
ContRange = rng1.Address
Debug.Print sht.Name
Debug.Print ContRange
Debug.Print Len(ContRange)
Next

End Sub

Thanks

EM
 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      25th Nov 2008
dim rArea as Range
For each rArea in rng1.Areas

do something with rArea,
but don't bother rebuilding a 255+ address because it'll fail when you try
to use it (depending on what you are doing)

Regards,
Peter T

"ExcelMonkey" <(E-Mail Removed)> wrote in message
news:3F58D2A8-76BC-4C33-9AE5-(E-Mail Removed)...
>I know I can pass all the contiguous ranges of cells with formulas as
>follows
> below. However this suffers from the 255 char limit. That is, if the
> range
> is greater than 255 then the cell address that is passed to the ContRange
> variable will be truncated. How do you get around this?
>
> Sub test2()
> Dim sht As Worksheet
> Dim ContRange As String
>
> For Each sht In ThisWorkbook.Worksheets
> Set rng1 = sht.Range("a1:iv65536").Cells.SpecialCells(xlFormulas)
> ContRange = rng1.Address
> Debug.Print sht.Name
> Debug.Print ContRange
> Debug.Print Len(ContRange)
> Next
>
> End Sub
>
> Thanks
>
> EM



 
Reply With Quote
 
ExcelMonkey
Guest
Posts: n/a
 
      25th Nov 2008
Excellent Point Peter. This works:

Sub test2()
Dim sht As Worksheet
Dim ContRange As String

For Each sht In ThisWorkbook.Worksheets
ContRange = ""
Counter = 0
Set rng1 = sht.Range("a1:iv65536").Cells.SpecialCells(xlFormulas)
For Each myArea In rng1.Areas
If Counter = 0 Then
ContRange = myArea.Address
Else
ContRange = ContRange & "," & myArea.Address
End If
Counter = Counter + 1
Next
Debug.Print sht.Name
Debug.Print ContRange
Next

End Sub


"Peter T" wrote:

> dim rArea as Range
> For each rArea in rng1.Areas
>
> do something with rArea,
> but don't bother rebuilding a 255+ address because it'll fail when you try
> to use it (depending on what you are doing)
>
> Regards,
> Peter T
>
> "ExcelMonkey" <(E-Mail Removed)> wrote in message
> news:3F58D2A8-76BC-4C33-9AE5-(E-Mail Removed)...
> >I know I can pass all the contiguous ranges of cells with formulas as
> >follows
> > below. However this suffers from the 255 char limit. That is, if the
> > range
> > is greater than 255 then the cell address that is passed to the ContRange
> > variable will be truncated. How do you get around this?
> >
> > Sub test2()
> > Dim sht As Worksheet
> > Dim ContRange As String
> >
> > For Each sht In ThisWorkbook.Worksheets
> > Set rng1 = sht.Range("a1:iv65536").Cells.SpecialCells(xlFormulas)
> > ContRange = rng1.Address
> > Debug.Print sht.Name
> > Debug.Print ContRange
> > Debug.Print Len(ContRange)
> > Next
> >
> > End Sub
> >
> > Thanks
> >
> > EM

>
>
>

 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      25th Nov 2008
That looks fine but what's the ultimate objective, particularly if that
address length is 255+

Regards,
Peter T

"ExcelMonkey" <(E-Mail Removed)> wrote in message
news:5A6E13AC-F134-484C-BF71-(E-Mail Removed)...
> Excellent Point Peter. This works:
>
> Sub test2()
> Dim sht As Worksheet
> Dim ContRange As String
>
> For Each sht In ThisWorkbook.Worksheets
> ContRange = ""
> Counter = 0
> Set rng1 = sht.Range("a1:iv65536").Cells.SpecialCells(xlFormulas)
> For Each myArea In rng1.Areas
> If Counter = 0 Then
> ContRange = myArea.Address
> Else
> ContRange = ContRange & "," & myArea.Address
> End If
> Counter = Counter + 1
> Next
> Debug.Print sht.Name
> Debug.Print ContRange
> Next
>
> End Sub
>
>
> "Peter T" wrote:
>
>> dim rArea as Range
>> For each rArea in rng1.Areas
>>
>> do something with rArea,
>> but don't bother rebuilding a 255+ address because it'll fail when you
>> try
>> to use it (depending on what you are doing)
>>
>> Regards,
>> Peter T
>>
>> "ExcelMonkey" <(E-Mail Removed)> wrote in message
>> news:3F58D2A8-76BC-4C33-9AE5-(E-Mail Removed)...
>> >I know I can pass all the contiguous ranges of cells with formulas as
>> >follows
>> > below. However this suffers from the 255 char limit. That is, if the
>> > range
>> > is greater than 255 then the cell address that is passed to the
>> > ContRange
>> > variable will be truncated. How do you get around this?
>> >
>> > Sub test2()
>> > Dim sht As Worksheet
>> > Dim ContRange As String
>> >
>> > For Each sht In ThisWorkbook.Worksheets
>> > Set rng1 = sht.Range("a1:iv65536").Cells.SpecialCells(xlFormulas)
>> > ContRange = rng1.Address
>> > Debug.Print sht.Name
>> > Debug.Print ContRange
>> > Debug.Print Len(ContRange)
>> > Next
>> >
>> > End Sub
>> >
>> > Thanks
>> >
>> > EM

>>
>>
>>



 
Reply With Quote
 
Jim Rech
Guest
Posts: n/a
 
      25th Nov 2008
>>Set rng1 = sht.Range("a1:iv65536").Cells.SpecialCells(xlFormulas)

A small point but this could be a little shorter and work in Excel 2007 too:

Set rng1 = sht.Cells.SpecialCells(xlFormulas)

--
Jim
"ExcelMonkey" <(E-Mail Removed)> wrote in message
news:5A6E13AC-F134-484C-BF71-(E-Mail Removed)...
| Excellent Point Peter. This works:
|
| Sub test2()
| Dim sht As Worksheet
| Dim ContRange As String
|
| For Each sht In ThisWorkbook.Worksheets
| ContRange = ""
| Counter = 0
| Set rng1 = sht.Range("a1:iv65536").Cells.SpecialCells(xlFormulas)
| For Each myArea In rng1.Areas
| If Counter = 0 Then
| ContRange = myArea.Address
| Else
| ContRange = ContRange & "," & myArea.Address
| End If
| Counter = Counter + 1
| Next
| Debug.Print sht.Name
| Debug.Print ContRange
| Next
|
| End Sub
|
|
| "Peter T" wrote:
|
| > dim rArea as Range
| > For each rArea in rng1.Areas
| >
| > do something with rArea,
| > but don't bother rebuilding a 255+ address because it'll fail when you
try
| > to use it (depending on what you are doing)
| >
| > Regards,
| > Peter T
| >
| > "ExcelMonkey" <(E-Mail Removed)> wrote in message
| > news:3F58D2A8-76BC-4C33-9AE5-(E-Mail Removed)...
| > >I know I can pass all the contiguous ranges of cells with formulas as
| > >follows
| > > below. However this suffers from the 255 char limit. That is, if the
| > > range
| > > is greater than 255 then the cell address that is passed to the
ContRange
| > > variable will be truncated. How do you get around this?
| > >
| > > Sub test2()
| > > Dim sht As Worksheet
| > > Dim ContRange As String
| > >
| > > For Each sht In ThisWorkbook.Worksheets
| > > Set rng1 = sht.Range("a1:iv65536").Cells.SpecialCells(xlFormulas)
| > > ContRange = rng1.Address
| > > Debug.Print sht.Name
| > > Debug.Print ContRange
| > > Debug.Print Len(ContRange)
| > > Next
| > >
| > > End Sub
| > >
| > > Thanks
| > >
| > > EM
| >
| >
| >

 
Reply With Quote
 
ExcelMonkey
Guest
Posts: n/a
 
      25th Nov 2008
Effectively I want to be able to isolate each contiguous range on each sheet.
I then want to be able to test to see if a specific cell falls within one of
those ranges (True/False). Given that the Range("a1:iv65536")) will never
exceed 255, I should not run into any 255 char limits. Given that each
myArea In rng1.Areas will be contiguous, they too will not exceed the 255
limit. I agree that the joining them in the string variable will potentially
exceed 255. However I will use the Split function to send them all
separately to a collection object or array and only deal with separately.

Regards

RK

"Peter T" wrote:

> That looks fine but what's the ultimate objective, particularly if that
> address length is 255+
>
> Regards,
> Peter T
>
> "ExcelMonkey" <(E-Mail Removed)> wrote in message
> news:5A6E13AC-F134-484C-BF71-(E-Mail Removed)...
> > Excellent Point Peter. This works:
> >
> > Sub test2()
> > Dim sht As Worksheet
> > Dim ContRange As String
> >
> > For Each sht In ThisWorkbook.Worksheets
> > ContRange = ""
> > Counter = 0
> > Set rng1 = sht.Range("a1:iv65536").Cells.SpecialCells(xlFormulas)
> > For Each myArea In rng1.Areas
> > If Counter = 0 Then
> > ContRange = myArea.Address
> > Else
> > ContRange = ContRange & "," & myArea.Address
> > End If
> > Counter = Counter + 1
> > Next
> > Debug.Print sht.Name
> > Debug.Print ContRange
> > Next
> >
> > End Sub
> >
> >
> > "Peter T" wrote:
> >
> >> dim rArea as Range
> >> For each rArea in rng1.Areas
> >>
> >> do something with rArea,
> >> but don't bother rebuilding a 255+ address because it'll fail when you
> >> try
> >> to use it (depending on what you are doing)
> >>
> >> Regards,
> >> Peter T
> >>
> >> "ExcelMonkey" <(E-Mail Removed)> wrote in message
> >> news:3F58D2A8-76BC-4C33-9AE5-(E-Mail Removed)...
> >> >I know I can pass all the contiguous ranges of cells with formulas as
> >> >follows
> >> > below. However this suffers from the 255 char limit. That is, if the
> >> > range
> >> > is greater than 255 then the cell address that is passed to the
> >> > ContRange
> >> > variable will be truncated. How do you get around this?
> >> >
> >> > Sub test2()
> >> > Dim sht As Worksheet
> >> > Dim ContRange As String
> >> >
> >> > For Each sht In ThisWorkbook.Worksheets
> >> > Set rng1 = sht.Range("a1:iv65536").Cells.SpecialCells(xlFormulas)
> >> > ContRange = rng1.Address
> >> > Debug.Print sht.Name
> >> > Debug.Print ContRange
> >> > Debug.Print Len(ContRange)
> >> > Next
> >> >
> >> > End Sub
> >> >
> >> > Thanks
> >> >
> >> > EM
> >>
> >>
> >>

>
>
>

 
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
How to zero out non-contiguous ranges Dean Microsoft Excel Programming 8 27th Sep 2007 05:50 AM
Non contiguous ranges AD108 Microsoft Excel Programming 4 23rd Nov 2006 03:59 PM
sorting non contiguous ranges gsh20 Microsoft Excel Misc 1 8th Sep 2005 04:50 PM
How do I limit input-length (char by char) into a Memo Field =?Utf-8?B?TkpT?= Microsoft Access VBA Modules 2 17th Nov 2004 04:29 PM
Non-contiguous ranges for chart Mike Boardman Microsoft Excel Misc 1 1st Aug 2004 10:39 PM


Features
 

Advertising
 

Newsgroups
 


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