+ Reply to Thread
Results 1 to 8 of 8

#Value! Error on Sheet1 in Excel 2003

  1. #1
    Registered User
    Join Date
    04-29-2017
    Location
    California
    MS-Off Ver
    2003
    Posts
    4

    #Value! Error on Sheet1 in Excel 2003

    Hi. I am new to visual basic. I have written a function for Excel 2003 that will put a value into another cell. I have written the function and put it into Module1 so that I have access to the function from Sheet1. I do have macros enabled. This function shows up under the function list, but will not run from Sheet1 and gives me an error of #Value!. If I goto the visual basic script editor (the code page) and hit run at the top of the screen, the function works fine. If I remark out the Range ("f4") line, the function will then work fine from Sheet1. I also saved the Excel file as a .xlsm file.

    I have searched all over the internet on this and cannot find a solution. Just partial code, which does not run in my function.

    Does anyone have any advice on this? In Sheet1 cell f6, I put = myFunWriteData().Here is the function code:


    Please Login or Register  to view this content.
    Last edited by FDibbins; 04-29-2017 at 02:43 AM.

  2. #2
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: #Value! Error on Sheet1 in Excel 2003

    try here: Excel Programming / VBA / Macros

  3. #3
    Registered User
    Join Date
    04-29-2017
    Location
    California
    MS-Off Ver
    2003
    Posts
    4

    Re: #Value! Error on Sheet1 in Excel 2003

    I have been to the link above and many other places on the internet. I even tried Excel 2010 to see if my old version of Excel was faulty. There is no difference and I can not find information directly related to my problem. I need guidance from someone who has created their own functions and seen this problem. I am sure it is a simple fix.

  4. #4
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: #Value! Error on Sheet1 in Excel 2003

    It was suggestion to check VBA forum.
    Your function has no argument(s)
    try here: User Defined Function or How to create UDF or Your own functions in VBA

    maybe something like this:
    Please Login or Register  to view this content.
    or I don't understand what you want to achieve
    Last edited by sandy666; 04-29-2017 at 05:15 AM.

  5. #5
    Registered User
    Join Date
    04-29-2017
    Location
    California
    MS-Off Ver
    2003
    Posts
    4

    Re: #Value! Error on Sheet1 in Excel 2003

    I know this function does not have any inputs. I simplified the code so that only the necessary parts are in the code to show the problem. I need to be able to run a function or sub from one cell (F6 for example) on Sheet1 and produce a result (as if I typed it directly) to another cell (F4 in this example) on the same Sheet1. I have read all the links you have suggested over the past few weeks and tried multiple ways to run a function from one cell and write to another. All of them work perfectly when you hit the Run option in the Visual Basic Script Editor, but when you go to Sheet1, type or pull down the function into F6 (or any cell), and hit enter, you get the #VALUE! error. I can read from any cell, but I cannot write to any cell except the one the function is in by returning the function value. I should be able to do this from everything I have read so far on the internet. I think there is a simple step that I am missing and cannot seem to find. Sandy, have you tried running my code on a new Excel file on Sheet1?

  6. #6
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: #Value! Error on Sheet1 in Excel 2003

    Any formula/function (doesn't matter wks or udf) cannot write value into another cell. You need vba to do this eg. if you change value somewhere your OnChange VBA will write any value to defined cell.
    Formula/Function can take value from another cell(s) and show itself only.

    pseudocode:
    OnChange
    if F4 will change
    [F6].Value = "Done"
    ......

    but I'm not vba hero and most of the time vba annoys me
    Last edited by sandy666; 04-29-2017 at 12:58 PM.

  7. #7
    Registered User
    Join Date
    04-29-2017
    Location
    California
    MS-Off Ver
    2003
    Posts
    4

    Re: #Value! Error on Sheet1 in Excel 2003

    Thank you for all your help, Sandy. You got me on the right track. You are right. Excel will not allow you to write a function that will write to another cell. I found some information on the web that enabled me to do what I was trying to do. You have to use a workaround. I am enclosing a few URLs that helped me to fix my problem. I am now able to monitor certain cells for modification, call my function, and hardcode the results to a target cell. I settled on the Worksheet_Change event to fix my code (the first URL listed). I was mysteriously losing data sometimes when I changed sheets.

    https://support.microsoft.com/en-us/help/213612/how-to-run-a-macro-when-certain-cells-change-in-excel

    http://stackoverflow.com/questions/12501759/vba-update-other-cells-via-user-defined-function

    https://sites.google.com/site/e90e50/excel-formula-to-change-the-value-of-another-cell

    Here is my vba code on sheet1:

    Private Sub Worksheet_Change(ByVal Target As Range)

    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Dim KeyCells As Range

    ' The variable KeyCells contains the cells that will cause an alert when they are changed.

    Set KeyCells = Sheet1.Range("J3:J12") 'KeyCells range

    If Not Application.Intersect(KeyCells, Range(Target.Address)) _
    Is Nothing Then
    ' Display a message when one of the designated cells has been changed.
    ' Place your code here.

    Sheet1.Range("J15").Value = mdLast(KeyCells.Address) 'Write to destination cell - no code
    ‘ MsgBox "Cell " & Target.Address & " has changed." ‘Uncomment to show message

    End If
    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    End Sub

  8. #8
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: #Value! Error on Sheet1 in Excel 2003

    Glad if it works for you

    01repsolv.gif

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. =+Sheet1!A1+Sheet1!B1+Sheet1!C1 macro to convert all linked ref to Values
    By chriszoma in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-20-2013, 02:44 PM
  2. merge book1,sheet1,book2,sheet1,book3,sheet1 ect
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-11-2013, 01:30 PM
  3. Excel 2003 VBA error 400
    By paraxis in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-19-2008, 09:03 AM
  4. Excel 2003 Error
    By wz4np1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2008, 03:53 PM
  5. Replies: 3
    Last Post: 02-13-2006, 11:30 AM
  6. [SOLVED] Excel 2003 Macro Error - Runtime error 1004
    By Cow in forum Excel General
    Replies: 2
    Last Post: 06-07-2005, 09:05 AM
  7. [SOLVED] VBA Error in Excel 2003
    By Mike Flory in forum Excel General
    Replies: 13
    Last Post: 03-30-2005, 02:06 PM
  8. VBA error in Excel 2003
    By vbjenny in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-14-2005, 09:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1