Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default What is the output of this code (CODE given)

Hello all,

Given below are two cases which is a part (excerpt) of a big bunch of
code. I am not able to interpret certain part of the code. I have given
those, below each case.

case1: (works correctly)

idex = target.value

Set rng1 = sh.Columns(1).Find( _
What:=idex, _
After:=sh.Range("A65536"), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

If Not rng1 Is Nothing Then
rng1.Interior.ColorIndex = 3
Set rng2 = rng1.Offset(0, 1).Resize(1, 255) ' ======= what
does this line mean?

I WOULD LIKE TO KNOW THE OUTPUT OF THE PREVIOUS LINE. I.E. WHAT WOULD
BE RNG2

case2: (error in last line)

idex = target.value

Set rng11 = sh.Columns(2).Find( _
What:=idex, _
After:=sh.Range("B65536"), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

If Not rng11 Is Nothing Then
rng11.Interior.ColorIndex = 3
' Debug.Print "1a", rng1.Address(0, 0, xlA1, True)
Set rng22 = rng11.Offset(0, 1).Resize(1, 255) '
============== Error '1004' Application '

defined or object defined error

IN THIS CASE, I AM TWEAKING THE CODE IN CASE 1 A LITTLE, BUT I GET AN
ERROR IN THE PREVIOUS LINE..

I think if I understand the last line in case1, I can fix the last line
in case2.
If someone could give the probable/possible reason for the error in
case2, I would deeply appreciate it.

Thanks,
Thulasiram

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default What is the output of this code (CODE given)

Set rng22 = rng11.Offset(0, 1).Resize(1, 255)

should be

Set rng22 = rng11.Offset(0, 1).Resize(1, 254)

rng11 is in column B

rng11.offset(0,1) is in column C

so 256 column -2 = 254


in the first case, since rng1 is in column B, it can be 255 cells wide.

--
Regards,
Tom Ogilvy

"Thulasiram" wrote in message
ps.com...
Hello all,

Given below are two cases which is a part (excerpt) of a big bunch of
code. I am not able to interpret certain part of the code. I have given
those, below each case.

case1: (works correctly)

idex = target.value

Set rng1 = sh.Columns(1).Find( _
What:=idex, _
After:=sh.Range("A65536"), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

If Not rng1 Is Nothing Then
rng1.Interior.ColorIndex = 3
Set rng2 = rng1.Offset(0, 1).Resize(1, 255) ' ======= what
does this line mean?

I WOULD LIKE TO KNOW THE OUTPUT OF THE PREVIOUS LINE. I.E. WHAT WOULD
BE RNG2

case2: (error in last line)

idex = target.value

Set rng11 = sh.Columns(2).Find( _
What:=idex, _
After:=sh.Range("B65536"), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

If Not rng11 Is Nothing Then
rng11.Interior.ColorIndex = 3
' Debug.Print "1a", rng1.Address(0, 0, xlA1, True)
Set rng22 = rng11.Offset(0, 1).Resize(1, 255) '
============== Error '1004' Application '

defined or object defined error

IN THIS CASE, I AM TWEAKING THE CODE IN CASE 1 A LITTLE, BUT I GET AN
ERROR IN THE PREVIOUS LINE..

I think if I understand the last line in case1, I can fix the last line
in case2.
If someone could give the probable/possible reason for the error in
case2, I would deeply appreciate it.

Thanks,
Thulasiram



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default What is the output of this code (CODE given)

Thanks Tom

Tom Ogilvy wrote:
Set rng22 = rng11.Offset(0, 1).Resize(1, 255)

should be

Set rng22 = rng11.Offset(0, 1).Resize(1, 254)

rng11 is in column B

rng11.offset(0,1) is in column C

so 256 column -2 = 254


in the first case, since rng1 is in column B, it can be 255 cells wide.

--
Regards,
Tom Ogilvy

"Thulasiram" wrote in message
ps.com...
Hello all,

Given below are two cases which is a part (excerpt) of a big bunch of
code. I am not able to interpret certain part of the code. I have given
those, below each case.

case1: (works correctly)

idex = target.value

Set rng1 = sh.Columns(1).Find( _
What:=idex, _
After:=sh.Range("A65536"), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

If Not rng1 Is Nothing Then
rng1.Interior.ColorIndex = 3
Set rng2 = rng1.Offset(0, 1).Resize(1, 255) ' ======= what
does this line mean?

I WOULD LIKE TO KNOW THE OUTPUT OF THE PREVIOUS LINE. I.E. WHAT WOULD
BE RNG2

case2: (error in last line)

idex = target.value

Set rng11 = sh.Columns(2).Find( _
What:=idex, _
After:=sh.Range("B65536"), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

If Not rng11 Is Nothing Then
rng11.Interior.ColorIndex = 3
' Debug.Print "1a", rng1.Address(0, 0, xlA1, True)
Set rng22 = rng11.Offset(0, 1).Resize(1, 255) '
============== Error '1004' Application '

defined or object defined error

IN THIS CASE, I AM TWEAKING THE CODE IN CASE 1 A LITTLE, BUT I GET AN
ERROR IN THE PREVIOUS LINE..

I think if I understand the last line in case1, I can fix the last line
in case2.
If someone could give the probable/possible reason for the error in
case2, I would deeply appreciate it.

Thanks,
Thulasiram


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
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
Shorten code to apply to all sheets except a few, instead of individually naming them, and later adding to code. Corey Excel Programming 3 December 11th 06 05:14 AM
Excel code convert to Access code - Concat & eliminate duplicates italia Excel Programming 1 September 12th 06 12:14 AM
Code runs without error but doesn't print output Robert Hargreaves Excel Programming 1 May 27th 05 06:43 PM
conditional format for vb code on pivot output BEE Excel Programming 2 December 22nd 03 12:25 AM


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