Solved

Issue with VBA and excel code

Posted on 2014-10-29
3
283 Views
Last Modified: 2014-10-29
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.
0
Comment
Question by:Uptime Legal Systems
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
Anthony Berenguel earned 500 total points
ID: 40411094
try this...
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)
    if GetValue  = 0 then
       getvalue = ""
    end if
End Function

Open in new window

0
 
LVL 6

Author Closing Comment

by:Uptime Legal Systems
ID: 40411098
That is perfect, exactly what I needed.  Thanks much!
0
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 40411134
Awesome! I'm glad you're sorted out. Have a good day!

ab
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question