VBA Script Errors on Excel Cell containing a Formula

I'm writing a VBA script.  When running the script I have a varible being set from a Excel cell containing a formula.  The script errors on this staement.  See below
        Range("O10").Select
        BlockSize = ActiveCell.FormulaR1C1 ' DID Block Size
Cell O10 contains "=VLOOKUP(A1,SP_DID_Range!A:Q,10,FALSE)"
The above formula produces the value 20
What I receive is the formula instead of value the formula produces.
I am trying retrieve the value and use it in another formula.  So "BlockSize" should equal 20 not "=VLOOKUP(A1,SP_DID_Range!A:Q,10,FALSE)"

If you want the A1-style formula, use the Formula property.
If you want the R1C1-style formula, use the FormulaR1C1 property.
If you want the value, use the Value property:
    BlockSize = Range("O10").Value
Note that it isn't necessary to select the cell.
Regards, Hans Vogelaar (http://www.eileenslounge.com)

Similar Messages

  • Illustrator VBA scripting 101 - via Excel

    This post will attempt to introduce newcomers to Illustrator Visual Basic Scripting (well, not actually vbs, but rather tru VBA, Visual Basic for Applications). I personally prefer vba over bvs for a number of reasons. First, I always have Excel and Illustrator open, so it makes sense for me use it to drive Ai. Second, I usually need to transfer data between the two programs. Third...I love the Excel IDE...ok, let's get right into it.
    - Open Excel
    - hit Alt+F11, to bring up the editor
    - in the Tools menu, click on References...
    - add a reference to "Adobe Illustrator CS5 Type Library"
    - in the Personal.xls (or in any other book) add a Module. Personal is a global workbook that is always available. If you don't see it, go back to Excel and record a macro, anything will do. That will create the Personal file.
    - and type the following in that module
    - we have to continue the tradition and do the "HelloWorld" script
    Sub helloWorld()
        Dim iapp As New Illustrator.Application
        Dim idoc As Illustrator.Document
        Dim iframe As Illustrator.TextFrame
        Set idoc = iapp.ActiveDocument
        Set iframe = idoc.TextFrames.Add
        iframe.Contents = "Hello World from Excel VBA!!"
        Set iframe = Nothing
        Set idoc = Nothing
        Set iapp = Nothing
    End Sub
    - save Personal book
    - open Illustrator and create a new document first
    - to run, move the cursor anywhere inside the Sub...End Sub and hit F5
    that's it for now...in the following posts we'll move the text to the middle of the page, create new documents, get data from an Excel Range to Illustrator, get data from Illustrator text frame to an Excel Range...and more, hopefully.
    questions? comments?

    Lesson 4: Creating Shapes, Working with Selections, writing data to Excel
    In the Illustrator world a shape is a....well, I'm not going to bore you with technical terms only rocket scientists would understand....let's just say a Circle is a shape, as well as a Rectangle or a Star, there much better than the actual definition. Then in the scripting lingo all shapes are pathItems.
    There are a number of ways of creating shapes, in this exercise well focus on using the various Methods of the PathItem Object.
    to create a Circle we'll use the Ellipse Method, all arguments are optional, if we don't supply any, the method uses default values.
    Ellipse
    ([top as Double]
    [, left as Double]
    [, width as Double]
    [, height as Double]
    [, reversed as Boolean]
    [, inscribed as Boolean])
    Dim icircle As Illustrator.PathItem
    Set icircle = idoc.PathItems.Ellipse(300, 300, 100, 100)
    similarly, to create a square, we use the Rectangle Method
    Dim isquare As Illustrator.PathItem
    Set isquare = idoc.PathItems.Rectangle(200, 200, 100, 100)
    and to make a star we use the...hum...the Star Method
    Dim istar As Illustrator.PathItem
    Set istar = idoc.PathItems.Star(400, 400, 100, 50, 5)
    now lets select the square and read some of its properties and write them down to Excel
    isquare.Selected = True
    get properties of the top most selection, in case we have many items selected, for now it should only be the square
        w = idoc.Selection(0).Width
        h = idoc.Selection(0).Height
        y = idoc.Selection(0).top
        x = idoc.Selection(0).left
    and lets write those values to Excel, using the Cells object this time. Make sure you have a blank Excel book open, it will write data to the first 4 rows, 2 first columns
        Cells(1, 1) = "width: "
        Cells(1, 2) = w
        Cells(2, 1) = "height: "
        Cells(2, 2) = h
        Cells(3, 1) = "top: "
        Cells(3, 2) = y
        Cells(4, 1) = "left: "
        Cells(4, 2) = x
    here's the complete code, from now on, we'll start every exercise with a blank Excel book and a blank Illustrator document, so please do that before runing.
    Sub lesson4shapes()
        Dim iapp As New Illustrator.Application
        Dim idoc As Illustrator.Document
        Dim icircle As Illustrator.PathItem
        Dim isquare As Illustrator.PathItem
        Dim istar As Illustrator.PathItem
        Set idoc = iapp.ActiveDocument
        Set icircle = idoc.PathItems.Ellipse(300, 300, 100, 100)
        Set isquare = idoc.PathItems.Rectangle(200, 200, 100, 100)
        Set istar = idoc.PathItems.Star(400, 400, 100, 50, 5)
        isquare.Selected = True
        w = idoc.Selection(0).Width
        h = idoc.Selection(0).Height
        y = idoc.Selection(0).top
        x = idoc.Selection(0).left
        Cells(1, 1) = "width: "
        Cells(1, 2) = w
        Cells(2, 1) = "height: "
        Cells(2, 2) = h
        Cells(3, 1) = "top: "
        Cells(3, 2) = y
        Cells(4, 1) = "left: "
        Cells(4, 2) = x
        Set istar = Nothing
        Set isquare = Nothing
        Set icircle = Nothing
        Set idoc = Nothing
        Set iapp = Nothing
    End Sub
    Note that the code we just wrote is not the most efficient way of doing things, we don't have to select an object in order to work on it (get the properties for instance). We did it for illustration purposes, we could also use a loop to write data to Excel. We'll do that in the next lesson.
    also, note that the top/left values don't match exactly with the values we entered (200, 200), homework, can you tell why?

  • Numbers error message: the spreadsheet contains more formula than are supported

    always using spreadsheets and taught the ipad would make things easier but it just threw up a new set of problems.
    What specifically causes this problem to occur, are there formula to be avoided or is it the amount of formula held in a file?
    What can i do to avoid this?
    Any way around it when it happens?
    Any help or insight would be very much appreciated

    This forum is dedicated to Numbers on Mac OS X.  You will get more help in the forum for iWork on iOS.
    https://discussions.apple.com/community/app_store/iwork_for_ios
    There is an online User' Guide which may be helpful to you:
    http://www.apple.com/support/ios/numbers/

  • Can't drag down a cell containing formula

    I've created a simple balance sheet (incoming outgoing) as I've done many times before.
    I can't drag down a cell containing the formula which creates the total balance, which I normally do by clicking on the cell, hovering over the bottom right hand corner until the + appears and then drag that down to cells below, which usually continues the formula.
    Here's the thing - I used to be able to do this in this document and I still can in another group of cells within the same document. It appears that this cell has become locked.
    I've tried deleting the entire column and starting from the top, but again, it won't drag down.
    Any ideas?
    Thanks in anticipation.
    Phil

    Hello
    Having the sheet in front of me gives the soluce.
    You merged cells from column F and cells from column G.
    When this is done we can't use the fill down feature.
    Use Split into Columns to separate cells F from cells G and you will get the original behaviour
    Yvan KOENIG (from FRANCE vendredi 18 avril 2008 16:47:49)

  • Applescript to determine if cell is a formula?

    Perhaps I'm missing the obvious, but I can't seem to find any applescript support for determining if a cell contains a formula or is a literal value. 'get cell value' returns the resolved value rather than the formula string, and there doesn't seem to be an 'isformula' boolean property, nor is 'formula' a valid cell formatting type.
    Any pointers?

    It's quite easy
    set rowNum to 80
    set colnum to 3
    set tName to 1
    set sName to 1
    set dName to 1
    set isFormula to my isItAformula(rowNum, colnum, tName, sName, dName)
    on isItAformula(rNum, cNum, t, s, d)
    try
    tell application "Numbers"
    tell document d to tell sheet s to tell table t
    set aCell to (get name of cell rNum of column cNum)
    set aRange to aCell & ":" & aCell
    set oldFormat to format of range aRange
    set format of range aRange to text
    set tVal to value of cell aCell
    set format of range aRange to oldFormat
    end tell -- document
    end tell -- Numbers
    return tVal starts with "="
    on error
    if my parleAnglais() then
    error "row " & rNum & " of column " & cNum & " is out of range !"
    else
    error "ligne " & rNum & " de la colonne " & cNum & " est hors limites !"
    end if
    end try
    end isItAformula
    --=====
    on parleAnglais()
    local z
    try
    tell application "Numbers" to set z to localized string "Cancel"
    on error
    set z to "Cancel"
    end try
    return (z is not "Annuler")
    end parleAnglais
    Yvan KOENIG (from FRANCE dimanche 26 avril 2009 22:59:49)

  • The query contains a formula with the operator SUMCT

    I m trying to get query ready for Webi, getting the error as 'The query contains a formula with the operator %RT. Therefore, the query cannot be released for OLE DB for OLAP'
    I have not used any kind of s %GT, %RT, %CT, SUMGT, SUMRT, SUMCT and LEAF, also i have suppressed results / over results from the query, over to it, i have removed the calculate results as 'summation' feature and set to 'not defined' for all of my key figures.
    Still getting the error...
    Please suggest.
    Niraj

    hi,
    Ensure that all Link IDs are visible in the lsdal.ini file  located in the \Windows\system directory of the PAS Server as those are then available to all users. The lsdal.ini file may not be correctly updated if: - You have created the BI Link IDs while using PAS in Client Server Mode - You have enabled multi user access for remote desktop. In this case an additional lsdal.ini file may appear in the user specific Windows directory of someone who may have remotely connected to the system to create the Link ID. That additional lsdal.ini file will only be valid for that specific user.
    Also try adding  "ODBOSECURITY=0" entry to the end of the c:\windows\lsserver.ini file on the server.
    hope it helps
    regards
    laksh

  • Error in Excel VBA script while using sharepoint web service

    Hi Can you please help me out  in this ?
    nain1987

    Hi Nain,
    According to your description, my understanding is that the error occurred in the Excel VBA scripts which was used to update SharePoint list.
    I recommend to check if the URL of the web service is in the right scope. If the list is in a subsite, the URL should be: http://servername/site/ _vti_bin/Lists.asmx.
    To update SharePoint list using Excel VBA script, you can refer to the link below:
    http://sharepoint.stackexchange.com/questions/34433/update-sharepoint-list-using-excel
    Best regards.
    Thanks
    Victoria Xia
    TechNet Community Support

  • How to protect Excel cells while allowing VBA to modify them?

    I want to allow users to modify inputs in some Unlocked cells and have the other cells update accordingly. I also want to prevent users from clobbering those other cells, so those are Locked.
    Protect Sheet allows ordinary formulas in Locked cells to execute but, by default, prevents VBA functions from executing when their input cells are modified. So, after consulting the
    Excel 2013 developer reference's descriptions of the Worksheet.Protect method and
    Worksheet object, I added these statements to my initialization routine:
    Worksheets(1).Activate
    ActiveSheet.Protect "", UserInterfaceOnly = True
    The 2nd statement enables Protect Sheet with a null password successfully, but the UserInterfaceOnly setting isn't having the effect I expected, i.e., allowing the VBA functions to execute when their input cells are changed. (I've noticed it seems to enable
    the Allow Users to Edit Objects protection option.)
    I also tried := True, but that doesn't help.

    The function fails because you cannot change characteristics of a chart in a worksheet function. A worksheet function can only return a value to the cell that contains the formula.
    You can use the Worksheet_Change event to modify the chart instead. The function can be simplified to
    Function Show_RGB(Y, u, v, Swatch) As Variant
    Dim R As Single, G As Single, B As Single
    On Error GoTo ErrHandler
    R = R_from_Yuv(Y, u, v)
    G = G_from_Yuv(Y, u, v)
    B = B_from_Yuv(Y, u, v)
    Show_RGB = Array(R, G, B) ' Allow <0 and >255 in spreadsheet
    ExitHandler:
    Exit Function
    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Function
    The Worksheet_Change event procedure in the worksheet module:
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim R As Single, G As Single, B As Single, Swatch As Integer
    Dim rng As Range
    On Error GoTo ErrHandler
    If Not Intersect(Range("B3:D14"), Target) Is Nothing Then
    Worksheets(1).Unprotect
    For Each rng In Intersect(Range("B3:D14"), Target)
    R = Cells(rng.Row, 5)
    G = Cells(rng.Row, 6)
    B = Cells(rng.Row, 7)
    Swatch = rng.Row - 2
    R = WorksheetFunction.Max(0, (WorksheetFunction.Min(255, R))) ' ...avoid runtime error when changing displayed color
    G = WorksheetFunction.Max(0, (WorksheetFunction.Min(255, G)))
    B = WorksheetFunction.Max(0, (WorksheetFunction.Min(255, B)))
    With Worksheets(1).ChartObjects(6).Chart.SeriesCollection(1)
    .Points(Swatch).MarkerBackgroundColor = RGB(R, G, B)
    .DataLabels(Swatch).Font.Color = RGB(R, G, B)
    End With
    Next rng
    End If
    ExitHandler:
    Worksheets(1).Protect
    Exit Sub
    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub
    See
    https://www.dropbox.com/s/nylonrp0y86lq1c/FAA%20palette%20designer%20Beta%2002.xlsm?dl=1
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

  • Transferring the values from a known range of cells (containing formulas) in Excel using Applescript

    I have my AppleScript iterating thru email messages and pasting data (which arrives via email from a web form) into following cells: range "A1:A50"
    My Excel parsing of data occurs in cell formulas on Row 52, cells in range "A52:AZ52"
    I want to copy the cells in row 52 and paste the Values (not the formulas) in successive rows underneath the formula cells, starting with row 54: range "A54:AZ54"
    In pseudo code the code snip is:
    tell worksheet "sheet1" of workbook "Example" application "Microsoft Excel"
         repeat i from 1 thru to (count emails)
              paste some of the contents of (email item i) into sheet range "A1:A50"  
                                            # the above forms about twenty lines of code to get it
                                                  into Excel's cell object list or lists
              copy or get row 52   # or range "A52:AZ52" if that's easier/faster/better
              paste or set the values of row 52 into row (53+i)
         end repeat
    end tell
    Not sure whether to use the clipboard with "paste speical…[range] with []" or copy and set value statements. I only know how to reference existing ranges, not the cell contents of the range. I really need to know how to get contents of cells into a AppleScript object (list) that I can transfer. The 2004 Excel AS documentation is not helping me, please throw me a life line someone. :-)

    One other question if I may hijack my thread, if I wanted to set the column of the range programatically how would I do that?
    I know how to programatically set the row eg.
         set x to 54
         set r to range "A" & x & ":AZ" & x
         set tVlaue to value of r
    But I need something like Column (x) to make one of {"A","B","C",…}
    but column(2) gives me $B:B$
    and: "column(2) as text" (so I can halve it) beachballs Script Debugger and Excel and I have to stop the script and restart Excel!

  • Trying to open a page in IE-tab using javascript, script type="text/javascript" window.location.href="chrome://coralietab/content/container.html?url=0,myurl" /script Error:Component returned failure code:0x80004005 (NS_ERROR_FAILURE) [nsIDOMLocation.href]

    I am trying to open a page in IE-tab using javascript like this, <script type="text/javascript"> window.location.href = "chrome://coralietab/content/container.html?url=0,myurl" ;</script>.Error occured : [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMLocation.href]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame ::myurl :: load :: line 234" data: no] I have IE-Tab plug-in installed..when I open the same link manually in mozilla,it works fine and page gets opened in Ie-tab.

    The only way this might be possible is by using the HostContainer object
    to access the HTML page and do it from there.

  • With Firefox running, Office 2007 generates a "Cannot Empty Clipboard" error message when pasting information between Excel cells -- the behavior goes away when I close Firefox. Is there a way to prevent this?

    I am running Windows XP, Office 2007, and Firefox 3.6.13.
    Whenever I have Firefox running in the background and I attempt to paste information between Excel cells a "Cannot Empty Clipboard" error is generated. I have attempted numerous other fixes for this: Excel and Office settings. But nothing seems to help. When I close Firefox, the errors are no longer generated.

    The Skype add-in was the culprit in my case. Disabling it fixed the problem. As soon as I enable it, the problem comes back.

  • Cells contain the word "ERROR"

    Hi,
    A report runs without any problems. The only strange thing is that some cells contain the amounts followed by the word ERROR (e.g.: 1.332,00 ERROR).
    This doesn't seem to be related to aggregation behaviour or different currencies/ units of measure (in that case you'd get a [], X, or *). I  don't recall having ever seen this in BEx.
    I already tried debugging it ("no parallel processing", "do not suppress warnings", breakpoint at message handler) but I couldn't find anything...
    Thanks,
    Gerrit

    Hi Gerrit,
    Pls. check the currency of the Amount field. if its not there then it will display with ERROR. or to remove the error use NODIM...
    Thanks,
    Vachan

  • Script to open excel files take info and put into new document

    Hi All
    I am new to applescript, but looking through the forums it seems to be the solution to my problem.
    I have large numbers of excel files on a pc server which i want to open, take approx 8 cells of information from each and place into a new excel doc, forming a list. I want this if possible to happen automatically, so if a new excel document is placed into a folder on the server, the relavent information is added to my list.
    I have looked at automator but dont think it works with excel yet, and the programming in excel is too much for me.
    I posted a query here in my previous job for a script of change all "/" symbols to "-" symbols, which worked very well and i hope someone more gifted can help with my new query.
    Hope i have given enough info and that someone can help
    thanks

    Supplied below is a, quick and dirty (minimal error handling), working self contained (applet) example:
    on run {}
    display dialog "Drag files onto applet for processing."
    end run
    on open (dragged_Items)
    try
    tell application "Microsoft Excel" -- Launch 'Excel' to process '.xls' files
    set tList to {} -- Create an empty list.
    repeat with i in dragged_Items -- Cycle through each dragged '.xls' file.
    open i -- Open each file.
    repeat with j from 1 to 8 -- Cycle through the eight column values of a single row.
    copy (value of cell j of row 3) to end of tList -- Obtain individul cells' value and place into 'tList'.
    end repeat
    end repeat
    repeat until (documents is {}) -- Routine to close all opened '.xls' windows. Here, 'close windows' does not work.
    close windows
    end repeat
    if (not (document 1 exists)) then make new document -- Create a new document, if needed.
    set k to 0 -- Location (position) of a 'tList' item.
    repeat with i from 1 to (count dragged_Items) -- Set row value, of where to ener column values.
    repeat with j from 1 to 8 -- Set cells' column value.
    set k to k + 1 -- Increment 'tList' location.
    set (value of cell j of row i) to (item k of tList) -- Enter value into current rows' columns' cell from 'tList'.
    end repeat
    end repeat
    activate -- Bring window to foreground.
    end tell
    end try
    end open
    Save the AppleScript code as an applet (application).
    Drag the desired files onto the applet for processing.
    The above AppleScript code obtains the cell values of columns A through H of row 3 of each '.xls' file.
    To automatically process the files of a specific folder - utilize the provided code, with respective modifications, within a
    'on adding folder items to this_folder after receiving these_items
    end adding folder items to
    ... AppleScript - 'Folder Action'.

  • VBA command changed in Excel 2010?

    We recently upgraded to Excel 2010, and a macro that always worked perfectly in 2007 is behaving strangely now.
    I use the following command to insert a picture into Microsoft Excel:
    Set pic = ActiveSheet.Pictures.Insert("C:\Pictures\Example.tif")
    (Sorry for not inserting the above in a code block, but my web browser kept timing out while waiting for it.)
    That VBA command used to work flawlessly, but ever since I upgraded to Office 2010 and email my new workbook with a picture added via a macro to anybody else
    on site, the picture is gone with this error message in its place:
    "The linked image cannot be displayed. The file may have been moved, renamed, or deleted. Verify that the link points to the correct file and location."
    What changed in Excel 2010 to cause my VBA script to insert a LINK to a picture instead of embedding the actual picture?  Does anybody with a similar
    macro have this problem?

    Hey G North,
    I had added a workaround to my code, but your one (1) line offers a better solution. 
    And you're right . . . my original code did include the top, left, height, and width parameters, and this was the workaround I came up with:
    Dim pic As Picture, rng As Range
    Set pic = ActiveSheet.Pictures.Insert("C:\Pictures\Example.tif")
    Set rng = ActiveWindow.RangeSelection
    With pic
    .Top = ActiveCell.Top
    .Left = ActiveCell.Left
    .ShapeRange.LockAspectRatio = msoFalse
    Resize the picture's Height and Width
    to match the Current Range.
    .ShapeRange.Height = rng.RowHeight
    .ShapeRange.Width = rng.Width
    .Placement = xlMoveAndSize
    .Cut
    End With
    ActiveSheet.Pictures.Paste.Select
    You'll notice that after I inserted my picture and resized it to fit the active range, I CUT it and then PASTED it in that same range as a PICTURE.
    But again, your single line of code is preferable.
    Thanks again!

  • EPMExecuteAPI error in excel input form

    Hello expert,
    I'd like to add an EPMExecuteAPI link in an Excel input form, but I get an error in the cell :
    #Error - Unexpected Error. Check your parameters.
    Here is the formula I set in the cell :
    =EPMExecuteAPI("DataManagerOpenViewStatusDialog";"View status")
    I also try
    =EPMExecuteAPI("DataManagerOpenViewStatusDialog()";"View status")
    According to the online PDF help this function is compatible with EPMExecuteAPI.
    I also find this string :
    Application.Run "EPMExecuteAPI", "DataManagerRunPackage", "", "Import", "Packages", ""
    Is it supposed to be used in a VBA macro and called from a button ? (right clic on the button and affect macro)
    My goal is to provide few functionalities through links or buttons in the sheet.
    Thanks for your help.
    G.
    No ideas ?
    Thanks
    Edited by: Société T-Systems on Feb 8, 2012 11:31 AM

    Hi all,
    I did not already solved my issue.
    As I say functions with no parameters works fine, like
    =EPMExecuteAPI("DataManagerOpenViewStatusDialog";"View packages Status")
    or
    =EPMExecuteAPI("SaveAndRefreshWorksheetData";"Save")
    but this particular one don't work :
    =EPMExecuteAPI("DataManagerRunPackage";"Run Allocation";"BS_Allocation,Financial Process,Public")
    I believe that the function is understood by excel since the cell displayed content is "Run Allocation", there is no #error message in the cell.
    When I double click in the cell like for other working function, I just go editing the function string (with another function the action is performed)
    So help is still welcome on this post
    Regards

Maybe you are looking for

  • Change encoding from utf-8 to iso-8859-1 in JMS receiver!

    Hi. I have some problems regarding encoding. The simple setup: dummy datatype as input, XSLT mapping and standard XI output(to JMS). Are there any way to tell the JMS adapter to deliver the message in iso-8859-1 and not utf-8? Regards Peter

  • HT204266 I have been charged twice for downloading an app what do I do?

    I have been charged twice for downloading an app and it wasn't the cheapest of spa- how do I resolve this?

  • Query on Bapi

    HI This is the query on BAPi,I have got one FS on Enhancement.i.e EPOS Upload program,that means i have to upload the data from Excel sheet to sap by using BAPI.I have one BAPI Name also,i.e XBAPI_RE_CN_SALES_REP_REPORT.This was given from onsite,i a

  • In operator and subquery

    I have created a sql query for oracle rdbms. I am passing a particular id in the subquery of my main query . I have one major difference in the query whenever i use a subquery with IN operator and using IN_list values in IN operator. I found that whe

  • -18002 error after Labview 7.1.1 upgrade

    Hi All, It seems like LV 7.1.1 upgrade is very dangerous when you use with Teststand. The existing system runs fine with LV 7.0 and TS 3.1. Now we have upgraded to LV 7.1.1. The LabVIEW adapter was set as LV 7.0 runtime engine previously. Now I could