Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default after a .Find command, offset the output 2 rows down.

so i have some information in blocks, in a selection i want to find the
first cell with the name "Elder" in it then move down 2 rows and check if
this cell has "Elder" also, if the cell (after offset) doesn't have "Elder"
in it then i want to save the cell as an Object to display in a ListBox later
in the program.

my problem is when i try to do the If(j.Offset (2, 0) < "Elder" Then... a
Run-time error '13 Type mismatch. pops up. is this type mismatch saying
that i cant do the .Offset on a variable that comes from a (Set j =
..Find("Elder",,,,xlByColumns)) command earlier in the script?

do i have to somehow change this variable (j) to a different type before i
can do a .Offset command on it?

thanks for any and all suggestions
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default after a .Find command, offset the output 2 rows down.


What have you declared J as? If it is a Range then it should work:


Code:
--------------------
If j.offset(2,0).Value < "Elder" Then 'etc
--------------------


--
royUK

Hope that helps, RoyUK
For tips & examples visit my 'web site' (http://www.excel-it.com/)
------------------------------------------------------------------------
royUK's Profile: http://www.thecodecage.com/forumz/member.php?userid=15
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=47036

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default after a .Find command, offset the output 2 rows down.

Well, i dont know if a .Find function declares a variable as a range.

this is a portion of my code.

With Selection
Set j = .Find("Elder", , , , xlByColumns)
If Not j Is Nothing Then
Set comp1 = j.Offset(2, 0)
If j.Offset(2, 0) < "Elder" Then
apmtAddress1 = j.Row
Set apmtcdn1 = j
apmtlist1 = j.Offset(2, 0)
Else
Set comp2 = j.Offset(2, 0)
Set j = .FindNext(j)
apmtlist1 = j.Offset(2, 0)
End If
................................(goes further with other If-thens)



even with putting the (.Value) in there after the .Offset(2, 0) it is
giving me the same error code.



"royUK" wrote:


What have you declared J as? If it is a Range then it should work:


Code:
--------------------
If j.offset(2,0).Value < "Elder" Then 'etc
--------------------


--
royUK

Hope that helps, RoyUK
For tips & examples visit my 'web site' (http://www.excel-it.com/)
------------------------------------------------------------------------
royUK's Profile: http://www.thecodecage.com/forumz/member.php?userid=15
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=47036


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default after a .Find command, offset the output 2 rows down.

Find won't declare any variables.

You would use something like:

Option Explicit
Sub YourSubNameHere()
dim J as range
dim compl = range
...

with selection
set j = .find(....

==========
One of the things that can cause this error is that if that j.offset(2,0)
contains an error.

You could check it with something like:

if iserror(j.offset(2,0).value) then
'skip it
elseif lcase(j.offset(2,0).value) = lcase("Elder") then
'do the work.
end if

If you want to see what's in that cell for debugging purposes, add this before
the offending line:

with j.offset(2, 0)
msgbox .address & vblf & .text
end with

And you'll be able to see what that cell holds.

Ironhydroxide wrote:

Well, i dont know if a .Find function declares a variable as a range.

this is a portion of my code.

With Selection
Set j = .Find("Elder", , , , xlByColumns)
If Not j Is Nothing Then
Set comp1 = j.Offset(2, 0)
If j.Offset(2, 0) < "Elder" Then
apmtAddress1 = j.Row
Set apmtcdn1 = j
apmtlist1 = j.Offset(2, 0)
Else
Set comp2 = j.Offset(2, 0)
Set j = .FindNext(j)
apmtlist1 = j.Offset(2, 0)
End If
...............................(goes further with other If-thens)

even with putting the (.Value) in there after the .Offset(2, 0) it is
giving me the same error code.

"royUK" wrote:


What have you declared J as? If it is a Range then it should work:


Code:
--------------------
If j.offset(2,0).Value < "Elder" Then 'etc
--------------------


--
royUK

Hope that helps, RoyUK
For tips & examples visit my 'web site' (http://www.excel-it.com/)
------------------------------------------------------------------------
royUK's Profile: http://www.thecodecage.com/forumz/member.php?userid=15
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=47036



--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default after a .Find command, offset the output 2 rows down.

I am still having problems with a Type mismatch Run-error. i have checked
the cell contents with the msgbox (.address & vblf § .Text) it returns $A$52
(which is correct) and Elder (which is also correct). thus my contents
should allow the if then to proceed without producing an error (the if then
statement produces the error)

i have also tried activating the cell and using activeCell to no avail.
this is driving me crazy.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default after a .Find command, offset the output 2 rows down.

Also i have defined the variable as range. and in debug when i hover over
the first portion of the if then statement it shows (j.Offset (4. 0).Value =
"Elder") which suggests that the if then should work.
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default after a .Find command, offset the output 2 rows down.

I don't have another guess.

Ironhydroxide wrote:

I am still having problems with a Type mismatch Run-error. i have checked
the cell contents with the msgbox (.address & vblf § .Text) it returns $A$52
(which is correct) and Elder (which is also correct). thus my contents
should allow the if then to proceed without producing an error (the if then
statement produces the error)

i have also tried activating the cell and using activeCell to no avail.
this is driving me crazy.


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default after a .Find command, offset the output 2 rows down.

Well, i found that i had a couple other faults, the variable was being
changed between the time that i dimensioned it and the time it was being
used. but the answer you gave before was correct. thanks for your help. I
owe you one (i have no idea how, what, and who you really are, but i still
owe you one)

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
Find, Copy offset to offset on other sheet, Run-time 1004. Finny[_3_] Excel Programming 10 December 7th 06 11:46 PM
getting vba shell command to execute batch and save output to a file Mad Scientist Jr Excel Programming 2 April 28th 06 03:00 PM
Excel has a "Find Next" command but no "Find Previous" command. Michael Fitzpatrick Excel Discussion (Misc queries) 2 January 10th 05 11:45 PM
Write Command Output keepITcool Excel Programming 0 July 15th 04 10:02 PM
Write Command Output jaf Excel Programming 0 July 15th 04 10:01 PM


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