Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default VBA Range Issue : Cannot programatically select more than 42 columns

I have a program that loops thru each rows in a worksheet and have to
highlight some rows based on a condition.
Following is the Algorithm

strMultipleRow = ""
Do While Cells(i, 1) < ""
If ValidEntry(Cells(i,1).value) = False Then
strMultipleRow = strMultipleRow & i & ":" & i & ","
End If
i = i + 1
Loop


strMultipleRow = Left(strMultipleRow, Len(strMultipleRow) - 1)

Range(strMultipleRow).Select


Everything works fine, I have only less than 42 rows to be selcted
(highlighted). If the number of rows to be selected goes above 43 it
returns an runtime error 404 : Method 'Range' of object Global failed.

I want to find out whether any limitation on the number of rows that
VBA can programatically highlight. What is the workaround ?

Someone suggested to prequalify the selection with "xlSheet". I tried
it and got the same behaviour. Works fine if it has less than 42 but
fails if greater than 43.

GURUS PLEASE HELP...

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default VBA Range Issue : Cannot programatically select more than 42 columns

I guess that the string is exceeding 255 characters. Try this instead

Dim rng As Range
strMultipleRow = ""
i = 1
Do While Cells(i, 1) < ""
If ValidEntry(Cells(i, 1).Value) = False Then
If rng Is Nothing Then
Set rng = Cells(i, 1)
Else
Set rng = Union(rng, Cells(i, 1))

End If
i = i + 1
Loop

If Not rng Is Nothing Then
rng.EntireRow.Select
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Learner" wrote in message
oups.com...
I have a program that loops thru each rows in a worksheet and have to
highlight some rows based on a condition.
Following is the Algorithm

strMultipleRow = ""
Do While Cells(i, 1) < ""
If ValidEntry(Cells(i,1).value) = False Then
strMultipleRow = strMultipleRow & i & ":" & i & ","
End If
i = i + 1
Loop


strMultipleRow = Left(strMultipleRow, Len(strMultipleRow) - 1)

Range(strMultipleRow).Select


Everything works fine, I have only less than 42 rows to be selcted
(highlighted). If the number of rows to be selected goes above 43 it
returns an runtime error 404 : Method 'Range' of object Global failed.

I want to find out whether any limitation on the number of rows that
VBA can programatically highlight. What is the workaround ?

Someone suggested to prequalify the selection with "xlSheet". I tried
it and got the same behaviour. Works fine if it has less than 42 but
fails if greater than 43.

GURUS PLEASE HELP...



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA Range Issue : Cannot programatically select more than 42 columns

It is a limitation of the string size you are building. Better is

Dim rng as Range

i = 1
Do While Cells(i, 1) < ""
If ValidEntry(Cells(i,1).value) = False Then
if rng is nothing then
set rng = cells(i,1)
else
set rng = union(rng,cells(i,1))
end if
End if
i = i + 1
Loop
if not rng is nothing then
rng.EntireRow.Select
End if


That will get you up to 8192 areas (not just rows).
--
Regards,
Tom Ogilvy

"Learner" wrote in message
oups.com...
I have a program that loops thru each rows in a worksheet and have to
highlight some rows based on a condition.
Following is the Algorithm

strMultipleRow = ""
Do While Cells(i, 1) < ""
If ValidEntry(Cells(i,1).value) = False Then
strMultipleRow = strMultipleRow & i & ":" & i & ","
End If
i = i + 1
Loop


strMultipleRow = Left(strMultipleRow, Len(strMultipleRow) - 1)

Range(strMultipleRow).Select


Everything works fine, I have only less than 42 rows to be selcted
(highlighted). If the number of rows to be selected goes above 43 it
returns an runtime error 404 : Method 'Range' of object Global failed.

I want to find out whether any limitation on the number of rows that
VBA can programatically highlight. What is the workaround ?

Someone suggested to prequalify the selection with "xlSheet". I tried
it and got the same behaviour. Works fine if it has less than 42 but
fails if greater than 43.

GURUS PLEASE HELP...



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default VBA Range Issue : Cannot programatically select more than 42 columns

WOW! Thanks guys! This is exactly what I was looking for...It worked
great!!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default VBA Range Issue : Cannot programatically select more than 42 columns

So good, so good, you got it twice :-)

Bob


"Learner" wrote in message
oups.com...
WOW! Thanks guys! This is exactly what I was looking for...It worked
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
Select different columns within a range Kiran Charts and Charting in Excel 0 March 8th 10 01:22 PM
Select updated data from a range of columns Alylia Excel Worksheet Functions 5 August 30th 05 01:53 PM
Changing Pivot Range Programatically - header row issue Scott Lyon[_2_] Excel Programming 3 July 22nd 04 04:29 AM
Programatically deleting Range Grant Reid Excel Programming 10 May 14th 04 03:07 PM
Select a range of columns based on active cell Tom Ogilvy Excel Programming 0 November 10th 03 05:09 PM


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