What is the output of this code (CODE given)

T

Thulasiram

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
 
T

Tom Ogilvy

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.
 
T

Thulasiram

Thanks Tom

Tom said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top