+ Reply to Thread
Results 1 to 5 of 5

Basic programming help

  1. #1
    MaR
    Guest

    Basic programming help

    Code:
    Function getsask(ByVal SaskNr As Integer, ByVal Target As Range)
    Dim a As Integer
    a = Target.Offset(1, 0).Value

    getsask = a
    End Function

    When I do =getsask(1, A1:A2) i get #VALUE!

    Any ideas how to correctly get Integer from cell?

  2. #2
    NickHK
    Guest

    Re: Basic programming help

    What do you expect the value of Range("A1:A2").Offset(1, 0).Value to be ?
    Will these values fit into a single integer ?

    So
    You need to check that Target is a single cell or take the .Value of the
    first cell in the range.
    Also, what if the .Value is not an integer ?

    NickHK

    "MaR" <[email protected]> wrote in message
    news:[email protected]...
    > Code:
    > Function getsask(ByVal SaskNr As Integer, ByVal Target As Range)
    > Dim a As Integer
    > a = Target.Offset(1, 0).Value
    >
    > getsask = a
    > End Function
    >
    > When I do =getsask(1, A1:A2) i get #VALUE!
    >
    > Any ideas how to correctly get Integer from cell?




  3. #3
    NickHK
    Guest

    Re: Basic programming help

    What do you expect the value of Range("A1:A2").Offset(1, 0).Value to be ?
    Will these values fit into a single integer ?

    So
    You need to check that Target is a single cell or take the .Value of the
    first cell in the range.
    Also, what if the .Value is not an integer ?

    NickHK

    "MaR" <[email protected]> wrote in message
    news:[email protected]...
    > Code:
    > Function getsask(ByVal SaskNr As Integer, ByVal Target As Range)
    > Dim a As Integer
    > a = Target.Offset(1, 0).Value
    >
    > getsask = a
    > End Function
    >
    > When I do =getsask(1, A1:A2) i get #VALUE!
    >
    > Any ideas how to correctly get Integer from cell?




  4. #4
    MaR
    Guest

    Re: Basic programming help

    What I'm doing is I'm trying to go through whole cells in range and check
    them by Value

    "NickHK" rašė:

    > What do you expect the value of Range("A1:A2").Offset(1, 0).Value to be ?
    > Will these values fit into a single integer ?
    >
    > So
    > You need to check that Target is a single cell or take the .Value of the
    > first cell in the range.
    > Also, what if the .Value is not an integer ?
    >
    > NickHK
    >
    > "MaR" <[email protected]> wrote in message
    > news:[email protected]...
    > > Code:
    > > Function getsask(ByVal SaskNr As Integer, ByVal Target As Range)
    > > Dim a As Integer
    > > a = Target.Offset(1, 0).Value
    > >
    > > getsask = a
    > > End Function
    > >
    > > When I do =getsask(1, A1:A2) i get #VALUE!
    > >
    > > Any ideas how to correctly get Integer from cell?

    >
    >
    >


  5. #5
    NickHK
    Guest

    Re: Basic programming help

    Yes, but you are passing A1:A2 as the range.
    so multiple values cannot be put in a single Integer

    This will work, assuming Range("A1").Offset(1,) contains a number in the
    range -32,768 to 32,767.
    =getsask(1, A1)

    Or this
    =getsask(1, A1:A2)
    if you change the function:
    Public Function GetSask(SaskNr As Integer, Target As Range) As Integer
    Dim a As Integer
    a = Target.Offset(1, 0).Range("A1").Value
    GetSask = a
    End Function

    Also, what is the purpose of SaskNr, as it is not used ?

    NickHK

    "MaR" <[email protected]> wrote in message
    news:[email protected]...
    > What I'm doing is I'm trying to go through whole cells in range and check
    > them by Value
    >
    > "NickHK" rase:
    >
    > > What do you expect the value of Range("A1:A2").Offset(1, 0).Value to be

    ?
    > > Will these values fit into a single integer ?
    > >
    > > So
    > > You need to check that Target is a single cell or take the .Value of the
    > > first cell in the range.
    > > Also, what if the .Value is not an integer ?
    > >
    > > NickHK
    > >
    > > "MaR" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > Code:
    > > > Function getsask(ByVal SaskNr As Integer, ByVal Target As Range)
    > > > Dim a As Integer
    > > > a = Target.Offset(1, 0).Value
    > > >
    > > > getsask = a
    > > > End Function
    > > >
    > > > When I do =getsask(1, A1:A2) i get #VALUE!
    > > >
    > > > Any ideas how to correctly get Integer from cell?

    > >
    > >
    > >




+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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