Results 1 to 6 of 6

Thread: Problem with error type mismatch

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    SOLVED: Problem with error type mismatch

    So several months ago, I managed to, with the help of other on this board, get a working version of a code to find the percentile of a list of XYZ files. Since that time, I went back to open up the code agan, and it now gives me an error type mismatch.

    I suppose I am a little confused because the cell values that I write to text are in fact Long values, but every time I try and run the code, it breaks and tells me that I have defined the wrong type of variable. (i.e. excel seems to think that a long value is not a long value).

    [VBA]Sub run_Click()
    Application.ScreenUpdating = False
    Starttime = Timer
    'Clear Contents
    Range("A2:B20000").ClearContents '"A2:B100000"
    Dim i As Long, nd As Long, MaxBuilding As Long, MinBuilding As Long
    Dim File_name As String, inc As Long, j As Long, volume As Long
    Dim TempDens() As Double
    inc = 1
    'For j = 0 To inc
    Do
    ReDim TempDens(1 To 2, 1 To 1) 'ReDim TempDens(1 To 2, 0 To 0)
    If Sheet1.Cells(inc, 17).Value = "" Then Exit Do
    File_name = Sheet1.Cells(inc, 17).Value
    'fetch data from the file
    Open File_name For Input As #1
    Do
    If EOF(1) Then Exit Do
    nd = nd + 1
    ReDim Preserve TempDens(1 To 2, 1 To nd) 'ReDim Preserve TempDens(1 To 2, 0 To nd)
    ' Input #1, Temp(nd), Dens(nd)
    Input #1, TempDens(1, nd), TempDens(2, nd)
    Loop
    Close #1
    'Display values on the worksheet
    With Sheets("Export_Output1")
    .Range("A2").Resize(nd, 2) = Application.Transpose(TempDens)
    nd = 0
    Erase TempDens
    'create a file
    'Open "c:\z_unit_write.txt" For Append As #2
    'Open "C:\Documents and Settings\Pascal\Desktop\z_unit_write.txt" For Append As #2
    Open "c:\Quad_45122E6105.txt" For Append As #2
    MaxBuilding = .Range("h12")
    MinBuilding = .Range("k12")
    volume = .Range("m13")
    Write #2, MaxBuilding, MinBuilding, volume, File_name
    Close #2
    'clear Contents
    .Range("A2:B20000").ClearContents 'A2:B100000
    End With
    inc = inc + 1
    Loop
    'Next j
    MsgBox (Timer - Starttime)
    Application.ScreenUpdating = True
    Stop
    End Sub[/VBA]

    It always breaks in the same place [VBA]MaxBuilding = .Range("h12")[/VBA]

    That cell value is always an integer since the file it reads in is an integer.

    Why would this be?


    aaron

    attached is my woorkbook.
    Last edited by aaronreyna; 10-09-2009 at 02:31 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •