Consulting

Results 1 to 8 of 8

Thread: formula to vba

  1. #1
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location

    formula to vba

    hi
    i need some help
    i havethis formula
    =RIGHT(B1,LEN(B1)-FIND(":",B1))
    how can i right this formula in vba code??
    thanks
    Oleg

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Hi Oleg,

    At it's simplest:
    ActiveCell.Value = "=RIGHT(B1,LEN(B1)-FIND("":"",B1))"
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    hi
    it does not work if i out instead of "B1" variable
    can i do this with variables?

  4. #4
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    Without using any worksheet functions.
    [VBA]ActiveCell.Value = Right(Range("B1"), _
    Len(Range("B1")) - InStr(Range("B1"), ":"))
    [/VBA]

  5. #5
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Hi Oleg,

    It is not clear what you want. Perhaps:
    [VBA]Dim i As Integer
    For i = 1 To 10
    ActiveSheet.Range("B" & i).Value = "=RIGHT(B" & i & ",LEN(B" & i & ")-FIND("":"",B" & i & "))"
    Next[/VBA]
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  6. #6
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    what i want that i have a variable "myvar" and it equals $G$291

    i need that i cell q1 i will see "G" and in q2 "291"

    sorry for explanations i an working online

    thanks for all the help you are given me

  7. #7
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    [VBA]Dim myvar As String
    myvar = ActiveSheet.Range("Q1").Value & ActiveSheet.Range("Q2").Value
    ActiveCell.Value = "=RIGHT(" & myvar & ",LEN(" & myvar & ")-FIND("":""," & myvar & "))"[/VBA]
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  8. #8
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Even though there really is, as far as I know, no difference in the execution, I would recommend using ".Formula" instead of ".Value", purely for the fact of debugging code or performing maintenance on it.

Posting Permissions

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