Link to home
Start Free TrialLog in
Avatar of Uptime Legal Systems
Uptime Legal SystemsFlag for United States of America

asked on

Issue with VBA and excel code

I have the two following blocks of code to pull data from an external excel sheet:

Sub Host03GetValue()
    p = "c:\Test\"
    'p is the path to the document'
    f = "HOST03.xls"
    'f is the filename of the excel sheet'
    s = "tabvInfo"
    's is the sheet name'
    a = "A16"
    'a is the reference cell'
    Application.ScreenUpdating = False
    For r = 2 To 42
        For c = 1 To 1
            a = Cells(r, c).Address
            Cells(r + 8, c + 1) = GetValue(p, f, s, a)
        Next c
    Next r
    Application.ScreenUpdating = True
End Sub

Open in new window


Public Function GetValue(path, file, sheet, ref)
'   Retrieves a value from a closed workbook
    Dim arg As String
'   Make sure the file exists
    If Right(path, 1) <> "\" Then path = path & "\"
    If Dir(path & file) = "" Then
        GetValue = "File Not Found"
        Exit Function
    End If
'   Create the argument
    arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
      Range(ref).Range("A1").Address(, , xlR1C1)
'   Execute an XLM macro
    GetValue = ExecuteExcel4Macro(arg)
End Function

Open in new window


The problem is that for the empty cells, it puts in a o rather than leaving it blank which is my desired effect.  I've tried added in a call for IsEmpty() but unfortunately I'm not able to get it to work properly due to my lack of experience with coding.  Any help/advice is appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Anthony Berenguel
Anthony Berenguel
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Uptime Legal Systems

ASKER

That is perfect, exactly what I needed.  Thanks much!
Awesome! I'm glad you're sorted out. Have a good day!

ab