+ Reply to Thread
Results 1 to 4 of 4

VBA Code Correction

  1. #1
    RichIT
    Guest

    VBA Code Correction

    Hi All, thanks a million in advance!

    my Current code is:

    Range ("B9").Select
    Dim i As Integer
    For i = 4 to 7
    ActiveCell.FormulaR1C1 = "R[-i]C[4]"
    Next i
    End Sub

    This does not work. Im trying to set cell B9= to A6 (in this example),
    then repeat the code with i=5 meaning B9 should now = A5 (in this
    example). Could anyone help please. Thanks

    Rich


  2. #2
    Tom Ogilvy
    Guest

    RE: VBA Code Correction

    Sub Dosomething()
    Range ("B9").Select
    Dim i As Integer
    For i = 4 to 7
    ActiveCell.FormulaR1C1 = "R[" & -i & "]C[-1]"
    Msgbox Activecell.formula
    Next i
    End Sub

    --
    Regards,
    Tom Ogilvy


    "RichIT" wrote:

    > Hi All, thanks a million in advance!
    >
    > my Current code is:
    >
    > Range ("B9").Select
    > Dim i As Integer
    > For i = 4 to 7
    > ActiveCell.FormulaR1C1 = "R[-i]C[4]"
    > Next i
    > End Sub
    >
    > This does not work. Im trying to set cell B9= to A6 (in this example),
    > then repeat the code with i=5 meaning B9 should now = A5 (in this
    > example). Could anyone help please. Thanks
    >
    > Rich
    >
    >


  3. #3
    RichIT
    Guest

    Re: VBA Code Correction

    Thanks Tom and Harald,

    However in both cases, the result is the actual Formula (i.e.
    R[-7]C[-4]) rather than the value of the resulting formula if that
    makes sense. I would like a value to be put into B9, and then using i
    (the for loop) give the value of the next cell.

    Any ideas ?????
    Tom Ogilvy wrote:
    > Sub Dosomething()
    > Range ("B9").Select
    > Dim i As Integer
    > For i = 4 to 7
    > ActiveCell.FormulaR1C1 = "R[" & -i & "]C[-1]"
    > Msgbox Activecell.formula
    > Next i
    > End Sub
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "RichIT" wrote:
    >
    > > Hi All, thanks a million in advance!
    > >
    > > my Current code is:
    > >
    > > Range ("B9").Select
    > > Dim i As Integer
    > > For i = 4 to 7
    > > ActiveCell.FormulaR1C1 = "R[-i]C[4]"
    > > Next i
    > > End Sub
    > >
    > > This does not work. Im trying to set cell B9= to A6 (in this example),
    > > then repeat the code with i=5 meaning B9 should now = A5 (in this
    > > example). Could anyone help please. Thanks
    > >
    > > Rich
    > >
    > >



  4. #4
    Tom Ogilvy
    Guest

    Re: VBA Code Correction

    Sub Dosomething()
    Range ("B9").Select
    Dim i As Integer
    For i = 4 to 7
    ActiveCell.FormulaR1C1 = "=R[" & -i & "]C[4]"
    ActiveCell.Value = ActiveCell.Value
    Msgbox "Value in B9 is " & ActiveCell.Value & vbnewline & _
    "Value came from " & Range("B9").Offset(-i,4).Address(0,0,xlA1)
    Next i
    End Sub
    --
    Regards,
    Tom Ogilvy

    --
    Regards,
    Tom Ogilvy



    "RichIT" wrote:

    > Thanks Tom and Harald,
    >
    > However in both cases, the result is the actual Formula (i.e.
    > R[-7]C[-4]) rather than the value of the resulting formula if that
    > makes sense. I would like a value to be put into B9, and then using i
    > (the for loop) give the value of the next cell.
    >
    > Any ideas ?????
    > Tom Ogilvy wrote:
    > > Sub Dosomething()
    > > Range ("B9").Select
    > > Dim i As Integer
    > > For i = 4 to 7
    > > ActiveCell.FormulaR1C1 = "R[" & -i & "]C[-1]"
    > > Msgbox Activecell.formula
    > > Next i
    > > End Sub
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > > "RichIT" wrote:
    > >
    > > > Hi All, thanks a million in advance!
    > > >
    > > > my Current code is:
    > > >
    > > > Range ("B9").Select
    > > > Dim i As Integer
    > > > For i = 4 to 7
    > > > ActiveCell.FormulaR1C1 = "R[-i]C[4]"
    > > > Next i
    > > > End Sub
    > > >
    > > > This does not work. Im trying to set cell B9= to A6 (in this example),
    > > > then repeat the code with i=5 meaning B9 should now = A5 (in this
    > > > example). Could anyone help please. Thanks
    > > >
    > > > Rich
    > > >
    > > >

    >
    >


+ 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