ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   What is the output of this code (CODE given) (https://www.excelbanter.com/excel-programming/380848-what-output-code-code-given.html)

Thulasiram[_2_]

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


Tom Ogilvy

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




Thulasiram[_2_]

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




All times are GMT +1. The time now is 11:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com