LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default problem with type mismatch error

On Sun, 12 Oct 2008 15:48:28 -0500, Dave Peterson
wrote:

I would continue to just plop the value into cell. I'd drop the old xlm code
completely.

Ps. I did change some of the variables (like JLGWhiz suggested).

I should have shared the modified code:


Dave,

Thank you for the follow up. I've learned a couple new things which
I'm always thankful for.

I have tried your code and have a few comments and questions. I did
rip out all the unnecessary code (like clearing the cell contents if
0) just to simplify the isolation of the cause of any error, and I
shortened the loop to speed up the process of getting results, and
finally I eliminated some variables and put explicit values in, again
just to simplify the code down to bare minimum.

The Option Explicit, this appears to require the need for every
variable to be declared in a Dim statement? What was the usefulness of
this?

Your code inserts the formula to reference the external workbook. And
I think I understand that .value = .value will replace the formula
with the value of the cell.

But here's the interesting result. When I run this code I get #REF in
each cell. Each time I subsequently run the macro the right contents
are inserted into the cell. Is there some command needed to cause the
formula inserted into the cell to be evaluated? BTW, the results were
the same with the source file located at its url over the internet or
with a copy of the file located in My Documents on my local drive.

Wanting simplify a little more I made a small spreadsheet called test
with data in a1 through A10 and put it in My Documents. Then I ran the
following code (which is identical to the simplifid code I used above
but now references this simple spreadsheet) and I get a different
error. The error is 1004, application or obect defined error on the
..formula statement.

I'm baffled by what is going on.

Here's the code for the last experiement I described.

Option Explicit
Sub Build_Report()

Dim arg As Variant
Dim myString As String
Dim myPath As String
Dim mySheet As String
Dim myFile As String
Dim r, i As Long
Dim a, Answer As String
Dim res As Variant
Dim test_string, both As String


myPath = "C:\Documents and Settings\keithjo\My Documents\"
myFile = "[test.xls]"
mySheet = "Sheet1'!"
myString = myPath & myFile & mySheet
MsgBox myString
For r = 1 To 10
a = Cells(r, 1).Address
arg = myString & Range(a).Range("A1").Address(, , xlR1C1)
With Cells(r, 1)
.Formula = "=" & arg
.Value = .Value
End With
Next r
End Sub


John Keith



 
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
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 6 November 9th 05 05:54 AM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 1 November 8th 05 04:21 AM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
Type mismatch error problem when dealing with Strings David Goodall[_2_] Excel Programming 4 June 30th 05 01:40 PM


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