Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Weird... type mismatch only half of the time


I have a GetValue function which returns a cell's value from a closed
workbook using the ExecuteExcel4Macro command. I have no problem
assigning the returned value to the corresponding cell of the active
sheet. However, when I store the return value in a variant called
"temp" to check for empty cells, half of the time it runs smoothly and
the other half it returns the error "Type mismatch". I bolded the line
that returns an error half of the time. Any suggestions?

Private Function GetValue(path, file, sheet, ref)

Dim arg As String

arg = "'" & path & "[" & file & "]" & sheet & "'!" &
Range(ref).Range("A1").address(, , xlR1C1)

GetValue = ExecuteExcel4Macro(arg)

End Function

Private Sub FilterData(InputFile, InputSheet, InputRow, OutputRow,
FileDone)

Dim temp As Variant

p = PathName(InputFile)
f = FileName(InputFile)
s = InputSheet

Application.ScreenUpdating = False

Do
temp = GetValue(p, f, s, Cells(InputRow, 1).address)
* If temp = 0 Or temp = "" Then FileDone = True *

If Not FileDone Then
For c = 1 To 20
a = Cells(InputRow, c).address
ActiveSheet.Cells(OutputRow, c) = GetValue(p, f, s, a)
Next c
InputRow = InputRow + 1
OutputRow = OutputRow + 1
End If

Application.ScreenUpdating = True

Exit Do
FileDone = True
Loop

End Sub


--
paulharvey
------------------------------------------------------------------------
paulharvey's Profile: http://www.excelforum.com/member.php...o&userid=25227
View this thread: http://www.excelforum.com/showthread...hreadid=387547

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Weird... type mismatch only half of the time

If temp is returning an error (#n/a, #div/0, etc), then using that in the
comparison will cause an error:

* If temp = 0 Or temp = "" Then FileDone = True *

I'd check first:

if iserror(temp) then
'do what you want
else
if temp= 0 _
or temp = "" then
Filedone = true
end if
end if

(I like the multi-line if/end if better--personal choice!)

paulharvey wrote:

I have a GetValue function which returns a cell's value from a closed
workbook using the ExecuteExcel4Macro command. I have no problem
assigning the returned value to the corresponding cell of the active
sheet. However, when I store the return value in a variant called
"temp" to check for empty cells, half of the time it runs smoothly and
the other half it returns the error "Type mismatch". I bolded the line
that returns an error half of the time. Any suggestions?

Private Function GetValue(path, file, sheet, ref)

Dim arg As String

arg = "'" & path & "[" & file & "]" & sheet & "'!" &
Range(ref).Range("A1").address(, , xlR1C1)

GetValue = ExecuteExcel4Macro(arg)

End Function

Private Sub FilterData(InputFile, InputSheet, InputRow, OutputRow,
FileDone)

Dim temp As Variant

p = PathName(InputFile)
f = FileName(InputFile)
s = InputSheet

Application.ScreenUpdating = False

Do
temp = GetValue(p, f, s, Cells(InputRow, 1).address)
* If temp = 0 Or temp = "" Then FileDone = True *

If Not FileDone Then
For c = 1 To 20
a = Cells(InputRow, c).address
ActiveSheet.Cells(OutputRow, c) = GetValue(p, f, s, a)
Next c
InputRow = InputRow + 1
OutputRow = OutputRow + 1
End If

Application.ScreenUpdating = True

Exit Do
FileDone = True
Loop

End Sub

--
paulharvey
------------------------------------------------------------------------
paulharvey's Profile: http://www.excelforum.com/member.php...o&userid=25227
View this thread: http://www.excelforum.com/showthread...hreadid=387547


--

Dave Peterson
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
run time error 13 type mismatch Rob Bovey Excel Programming 3 April 13th 10 12:09 PM
run-time 13 Type mismatch simonsmith Excel Discussion (Misc queries) 2 May 18th 06 04:14 PM
Run-time error '13':Type mismatch Sibilia[_9_] Excel Programming 2 July 3rd 05 08:54 PM
run time error 13 type mismatch kkknie[_170_] Excel Programming 0 July 20th 04 03:28 PM
Run Time Error '13' Type mismatch David Adamson[_3_] Excel Programming 2 June 10th 04 04:00 AM


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