Solved

Issue with VBA and excel code

Posted on 2014-10-29
3
285 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Make the most of your online learning experience.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

696 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