Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Variable help (Excel 2000)

    Hi all,
    I'm trying to use the mid function with a variable, the range A1 is ABCDE, what I would to do is take y and crop it to "CD" at the moment I'm getting a 424 error....should this be a function?

    Public Sub Dimm()
    Dim x As String
    Dim y As String
    x = Sheets("Sheet1").Range("A1").Value
    y = Mid(x, 2, 2).Value
    End Sub

    Thanks,
    Darryl.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Variable help (Excel 2000)

    Mid is not an object, so you don't need the .Value after it. And since you want to start at the 3rd character, use

    y = Mid(x, 3, 2)

    BTW, I assume more code is to follow after this line, otherwise nothing will be done with the value.

  3. #3
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Re: Variable help (Excel 2000)

    Thank you Hans.

  4. #4
    3 Star Lounger
    Join Date
    May 2002
    Location
    Mpls, Minnesota, USA
    Posts
    271
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Variable help (Excel 2000)

    I was too slow again!

    Sub Macro1()
    '
    '
    Dim x As String
    Dim y As String
    x = Sheets("Sheet1").Range("A1").Value
    y = Mid(x, 2, 2)
    'then what ever you wish to do with y
    End Sub
    Chuck
    Chuck Reimer
    I'm from the Government and I'm here to help...

Posting Permissions

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