View Single Post
  #3 (permalink)  
Old September 7th, 2007, 06:16 AM
royUK royUK is offline
Registered User
 
Join Date: Sep 2007
Location: Mablethorpe, Lincolnshire, United Kingdom.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You give Filename a value, but you do not use it.

You declare compfile as a Workbook, but you don't give it a value.As a result the following line gives you the error:

            If (Sheet1.Columns.Cells(rowcount, column) = compfile.Worksheets("Lab Result-Order Code").Cells(trow, tcol).Value) Then

This is also wrong

If (Sheet1.Columns.Cells(rowcount, column)


Try

Option Explicit

Sub mUpdate()
    Dim vtest As Boolean, ctest As Boolean, return1 As Integer, rowcount As Integer, column As Integer, count As Integer
    Dim compfile As Workbook, tcol As Integer, trow As Integer, filename As String


    Set compfile = Workbooks.Open("C:\Users\lthuynh\Documents\MH\Lab Data Collection_ final_aag2.xls")


    count = 0
    rowcount = 3
    column = 2
    tcol = 1
    trow = 1
    ctest = True
    vtest = True

    return1 = MsgBox("Update the spreadsheet?", vbOKCancel, "Updating the spreadsheet")
    If return1 = 1 Then
        While vtest
            If rowcount < 2106 Then

                While ctest

                    If Sheet1.Cells(rowcount, column).Value = compfile.Worksheets("Lab Result-Order Code").Cells(trow, tcol).Value Then
                        Sheet1.Cells(rowcount, 4) = compfile.Worksheets("Lab Result-Order Code").Cells(trow, 5).Value
                        ctest = False
                    ElseIf rowcount > 3093 Then
                        ctest = False
                    Else
                        trow = trow + 1
                    End If
                Wend
                rowcount = rowcount + 1
            Else
                vtest = False
            End If
        Wend
    End If

End Sub













Hope that helps

Roy
Reply With Quote