Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default If Cells.Find can't find anything

Excel Experts,

I think I want to create an If/Then structure based on whether Cells.Find
finds what it is looking for. More specifically,

My code copies a number of values from Workbook "NCEntry" to "MNC". Each of
the values has a label in the cell to the left of it. Some of the values are
always there but others are only there on some days.

Simplified, my workbooks and code are as follows:

Workbook "NCEntry"

A B
1 MnrT4 500
2 MnrWA 1000


Workbook "NCEntry"

A B
1 4TT4 500
2 77WA 1000


<Code
Sub Update4TT4_4TT5_77WAWB()

Windows("NCEntry").Activate
Sheets("IEAccts").Select

On Error Resume Next

Cells.Find(What:="MnrT4").Offset(, 1).Select
Set MnrT4 = Selection

Cells.Find(What:="MnrWA").Offset(, 1).Select
Set MnrWA = Selection


Windows("MNC").Activate
Sheets("NetCap").Select

Cells.Find(What:="4TT4", After:=ActiveCell, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext).Offset(, 1).Select
Selection.Formula = "=" & MnrT4.Value & "+RC[1]"


Cells.Find(What:="77WA", After:=ActiveCell, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext).Offset(, 1).Select
Selection.ClearContents
Selection.Value = MnrWA

End Sub


My problem is that the entry MnrWA is not on sheet NCEntry every day. On
those days, the variable MnrWA gets set to the value for MnrT4 since that was
the last cell selected.

What I want to add to my code is something that says

If Cells.Find(What:="MnrWA").Offset(,1).Select doesn't find anything Then

Do Nothing

Else

Set MnrWA = Selection


End If

What code would I add to do this.

I recognize that I could change the structure to

Set MnrWA = Cells.Find(What:="MnrWA").Offset(,1)

but I need to use a similar test in other situations so I am interested in
how to do it with the If..Then structure.

Thanks in advance,
Alan

--
achidsey
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default If Cells.Find can't find anything

Any time you sue find code you really need to use a range object to deal with
exactly this issue of not finding anything

dim rngFound as Range

set rngFound = Cells.Find("MnrT4")
if rngfound is nothing then
msgbox "Couldn't Find MnrT4"
else
rngfound.select
endif

or something like that...
--
HTH...

Jim Thomlinson


"achidsey" wrote:

Excel Experts,

I think I want to create an If/Then structure based on whether Cells.Find
finds what it is looking for. More specifically,

My code copies a number of values from Workbook "NCEntry" to "MNC". Each of
the values has a label in the cell to the left of it. Some of the values are
always there but others are only there on some days.

Simplified, my workbooks and code are as follows:

Workbook "NCEntry"

A B
1 MnrT4 500
2 MnrWA 1000


Workbook "NCEntry"

A B
1 4TT4 500
2 77WA 1000


<Code
Sub Update4TT4_4TT5_77WAWB()

Windows("NCEntry").Activate
Sheets("IEAccts").Select

On Error Resume Next

Cells.Find(What:="MnrT4").Offset(, 1).Select
Set MnrT4 = Selection

Cells.Find(What:="MnrWA").Offset(, 1).Select
Set MnrWA = Selection


Windows("MNC").Activate
Sheets("NetCap").Select

Cells.Find(What:="4TT4", After:=ActiveCell, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext).Offset(, 1).Select
Selection.Formula = "=" & MnrT4.Value & "+RC[1]"


Cells.Find(What:="77WA", After:=ActiveCell, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext).Offset(, 1).Select
Selection.ClearContents
Selection.Value = MnrWA

End Sub


My problem is that the entry MnrWA is not on sheet NCEntry every day. On
those days, the variable MnrWA gets set to the value for MnrT4 since that was
the last cell selected.

What I want to add to my code is something that says

If Cells.Find(What:="MnrWA").Offset(,1).Select doesn't find anything Then

Do Nothing

Else

Set MnrWA = Selection


End If

What code would I add to do this.

I recognize that I could change the structure to

Set MnrWA = Cells.Find(What:="MnrWA").Offset(,1)

but I need to use a similar test in other situations so I am interested in
how to do it with the If..Then structure.

Thanks in advance,
Alan

--
achidsey

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default If Cells.Find can't find anything


Jim,

Thanks again.

Alan

--
achidsey


"achidsey" wrote:

Excel Experts,

I think I want to create an If/Then structure based on whether Cells.Find
finds what it is looking for. More specifically,

My code copies a number of values from Workbook "NCEntry" to "MNC". Each of
the values has a label in the cell to the left of it. Some of the values are
always there but others are only there on some days.

Simplified, my workbooks and code are as follows:

Workbook "NCEntry"

A B
1 MnrT4 500
2 MnrWA 1000


Workbook "NCEntry"

A B
1 4TT4 500
2 77WA 1000


<Code
Sub Update4TT4_4TT5_77WAWB()

Windows("NCEntry").Activate
Sheets("IEAccts").Select

On Error Resume Next

Cells.Find(What:="MnrT4").Offset(, 1).Select
Set MnrT4 = Selection

Cells.Find(What:="MnrWA").Offset(, 1).Select
Set MnrWA = Selection


Windows("MNC").Activate
Sheets("NetCap").Select

Cells.Find(What:="4TT4", After:=ActiveCell, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext).Offset(, 1).Select
Selection.Formula = "=" & MnrT4.Value & "+RC[1]"


Cells.Find(What:="77WA", After:=ActiveCell, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext).Offset(, 1).Select
Selection.ClearContents
Selection.Value = MnrWA

End Sub


My problem is that the entry MnrWA is not on sheet NCEntry every day. On
those days, the variable MnrWA gets set to the value for MnrT4 since that was
the last cell selected.

What I want to add to my code is something that says

If Cells.Find(What:="MnrWA").Offset(,1).Select doesn't find anything Then

Do Nothing

Else

Set MnrWA = Selection


End If

What code would I add to do this.

I recognize that I could change the structure to

Set MnrWA = Cells.Find(What:="MnrWA").Offset(,1)

but I need to use a similar test in other situations so I am interested in
how to do it with the If..Then structure.

Thanks in advance,
Alan

--
achidsey

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
Need Cells.find to find first number in a row which is 8000 Kasper Excel Discussion (Misc queries) 9 December 15th 08 02:10 PM
Find First Non blank cell than find column header and return that value Silver Rose Excel Worksheet Functions 10 April 30th 07 05:56 PM
Despite data existing in Excel 2002 spreadsheet Find doesn't find AnnieB Excel Discussion (Misc queries) 1 June 16th 06 02:15 AM
find and delete duplicate entries in two columns or find and prin. campare 2 columns of numbers-find unique Excel Programming 1 November 24th 04 04:09 PM
find and delete text, find a 10-digit number and put it in a textbox Paul Excel Programming 3 November 16th 04 04:21 PM


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