+ Reply to Thread
Results 1 to 7 of 7

name variable with 3 first characters of active cell

  1. #1
    shark102
    Guest

    name variable with 3 first characters of active cell

    hello

    another (I am sure) banal problem I am not able to cope with.

    I need to name a variable named after 3 first characters of active cell.

    I tried
    dim var
    var = left(activecell.value, 3)

    i tried also
    dim var, var1
    var = activecell.value
    var1 = left(var, 3)
    as suggested in one of the threads

    but I always get an error on this line of code

    active cell contains text

    any help appreciated

    thanks in advance



  2. #2

    Re: name variable with 3 first characters of active cell

    Sorry,

    I have tried the following code

    Sub test()
    Dim var, var1
    var = ActiveCell.Value
    var1 = Left(var, 3)
    Debug.Print var1
    End Sub

    and it worked fine on my machine (Excel 2000). There should not be a
    problem with your code but I guess that doesn't help you.


  3. #3
    Executor
    Guest

    Re: name variable with 3 first characters of active cell

    I have created this:

    Public Sub threeChars()
    Dim strValue As String
    '
    strValue = ActiveCell.Text
    strValue = strValue & "___"
    ' 3 extra characters so next statement will not gif an error
    strValue = Left(strValue, 3)

    MsgBox strValue
    End Sub

    Check your regional settings you might need:

    Public Sub threeChars()
    Dim strValue As String
    '
    strValue = ActiveCell.Text
    strValue = strValue & "___"
    ' 3 extra characters so next statement will not gif an error
    strValue = Left(strValue; 3)

    MsgBox strValue
    End Sub


    Hoop This Helps

    Executor


  4. #4
    Norman Jones
    Guest

    Re: name variable with 3 first characters of active cell

    Hi Shark,

    your variable assignments work for me.

    What error are you getting?

    What is the code which produces the error?

    ---
    Regards,
    Norman



    "shark102" <[email protected]> wrote in message
    news:[email protected]...
    > hello
    >
    > another (I am sure) banal problem I am not able to cope with.
    >
    > I need to name a variable named after 3 first characters of active cell.
    >
    > I tried
    > dim var
    > var = left(activecell.value, 3)
    >
    > i tried also
    > dim var, var1
    > var = activecell.value
    > var1 = left(var, 3)
    > as suggested in one of the threads
    >
    > but I always get an error on this line of code
    >
    > active cell contains text
    >
    > any help appreciated
    >
    > thanks in advance
    >
    >




  5. #5
    Tom Ogilvy
    Guest

    Re: name variable with 3 first characters of active cell

    In the VBE, go to Tools=>References and see if you have a reference marked
    as MISSING. If you find one, you need to eliminate it as a reference or fix
    it.

    In the meantime, instead of Left, use VBA.Left

    --
    Regards,
    Tom Ogilvy

    "shark102" <[email protected]> wrote in message
    news:[email protected]...
    > hello
    >
    > another (I am sure) banal problem I am not able to cope with.
    >
    > I need to name a variable named after 3 first characters of active cell.
    >
    > I tried
    > dim var
    > var = left(activecell.value, 3)
    >
    > i tried also
    > dim var, var1
    > var = activecell.value
    > var1 = left(var, 3)
    > as suggested in one of the threads
    >
    > but I always get an error on this line of code
    >
    > active cell contains text
    >
    > any help appreciated
    >
    > thanks in advance
    >
    >




  6. #6
    shark102
    Guest

    Re: name variable with 3 first characters of active cell

    I always get word keft highlighted (and it does not start with capital letter
    as it should) and message error is
    - compile error: wrong number of argumewnts or invalid property assignment

    I am confused

    "Norman Jones" wrote:

    > Hi Shark,
    >
    > your variable assignments work for me.
    >
    > What error are you getting?
    >
    > What is the code which produces the error?
    >
    > ---
    > Regards,
    > Norman
    >
    >
    >
    > "shark102" <[email protected]> wrote in message
    > news:[email protected]...
    > > hello
    > >
    > > another (I am sure) banal problem I am not able to cope with.
    > >
    > > I need to name a variable named after 3 first characters of active cell.
    > >
    > > I tried
    > > dim var
    > > var = left(activecell.value, 3)
    > >
    > > i tried also
    > > dim var, var1
    > > var = activecell.value
    > > var1 = left(var, 3)
    > > as suggested in one of the threads
    > >
    > > but I always get an error on this line of code
    > >
    > > active cell contains text
    > >
    > > any help appreciated
    > >
    > > thanks in advance
    > >
    > >

    >
    >
    >


  7. #7
    Tom Ogilvy
    Guest

    Re: name variable with 3 first characters of active cell

    That sounds like you have greated a variable, function or sub named LEFT.
    You need to give this a new name. It may not be that easy to fix. You can
    try exiting Excel and reopening. If that doesn't help, export all your code
    modules and delete them in the workbook, then save the workbook. Then
    import the code again.

    --
    Regards,
    Tom Ogilvy

    "shark102" <[email protected]> wrote in message
    news:[email protected]...
    > I always get word keft highlighted (and it does not start with capital

    letter
    > as it should) and message error is
    > - compile error: wrong number of argumewnts or invalid property assignment
    >
    > I am confused
    >
    > "Norman Jones" wrote:
    >
    > > Hi Shark,
    > >
    > > your variable assignments work for me.
    > >
    > > What error are you getting?
    > >
    > > What is the code which produces the error?
    > >
    > > ---
    > > Regards,
    > > Norman
    > >
    > >
    > >
    > > "shark102" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > hello
    > > >
    > > > another (I am sure) banal problem I am not able to cope with.
    > > >
    > > > I need to name a variable named after 3 first characters of active

    cell.
    > > >
    > > > I tried
    > > > dim var
    > > > var = left(activecell.value, 3)
    > > >
    > > > i tried also
    > > > dim var, var1
    > > > var = activecell.value
    > > > var1 = left(var, 3)
    > > > as suggested in one of the threads
    > > >
    > > > but I always get an error on this line of code
    > > >
    > > > active cell contains text
    > > >
    > > > any help appreciated
    > > >
    > > > thanks in advance
    > > >
    > > >

    > >
    > >
    > >




+ 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