Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Find and Write data

This procedure is not working. After the procedure has run, I can go to
editfind and it finds my value whats wrong here, please help. It displays
the message for error 91.

Private Sub CommandButton1_Click()

Dim x As Workbook

OrderToFind = ActiveSheet.Range("E17").Value
TrackingWorkbook = "\\Fs1\Material\Scheduling\OrderTracking.xls"
myvalue = ActiveSheet.Range("F15").Value


' Check if workbook is already opened.
On Error Resume Next
Set x = Workbooks("OrderTracking1")
If Err = 0 Then
Windows("OrderTracking1").Activate
Else
Workbooks.Open Filename:=TrackingWorkbook
End If

Sheets("To Finish").Select
'Find the order numbers comment line
Cells.Find(What:=OrderToFind & " Count", LookIn:=xlValues,
LookAt:=xlPart).Activate

If Err = "91" Then
MsgBox "Could not find Order#: " & OrderToFind
Exit Sub
End If

'Offset to the correct column and insert data
ActiveCell.Offset(, 32).Value = myvalue

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Find and Write data

You are best not teo generate errors whenever possible (they have a lot of
overhead associated with them that slows things down) Here is some better
code that will avoid the error

dim rngFound as range

set rngFound = cells.find((What:=OrderToFind & " Count", LookIn:=xlValues,
LookAt:=xlPart)

if rngFound is nothing then
msgbox "Not Found"
else
rngFound.offset(0,32).value = myvalue
endif

set rngfound = nothing

You will have to paste this into your code as appropriate...

HTH


"James W." wrote:

This procedure is not working. After the procedure has run, I can go to
editfind and it finds my value whats wrong here, please help. It displays
the message for error 91.

Private Sub CommandButton1_Click()

Dim x As Workbook

OrderToFind = ActiveSheet.Range("E17").Value
TrackingWorkbook = "\\Fs1\Material\Scheduling\OrderTracking.xls"
myvalue = ActiveSheet.Range("F15").Value


' Check if workbook is already opened.
On Error Resume Next
Set x = Workbooks("OrderTracking1")
If Err = 0 Then
Windows("OrderTracking1").Activate
Else
Workbooks.Open Filename:=TrackingWorkbook
End If

Sheets("To Finish").Select
'Find the order numbers comment line
Cells.Find(What:=OrderToFind & " Count", LookIn:=xlValues,
LookAt:=xlPart).Activate

If Err = "91" Then
MsgBox "Could not find Order#: " & OrderToFind
Exit Sub
End If

'Offset to the correct column and insert data
ActiveCell.Offset(, 32).Value = myvalue

End Sub

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
Macro:- Find first blank cell and write text Mac0001UK Excel Worksheet Functions 4 May 17th 09 02:34 AM
how do I write the formula to find the mean in a column of number lallen Excel Worksheet Functions 2 January 18th 08 08:27 PM
trying to write function to find data in last row in 1 column belvy123 Excel Discussion (Misc queries) 1 January 20th 07 01:58 PM
is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data? Daniel Excel Worksheet Functions 1 June 23rd 05 11:38 PM
VBA - Find every occurance of string in workbook, write to 1st she Doug Excel Programming 1 November 15th 04 03:19 AM


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