+ Reply to Thread
Results 1 to 4 of 4

Modifying VB Code:Excell Macro and Visal Basic Programming

Hybrid View

  1. #1
    Registered User
    Join Date
    08-27-2009
    Location
    GR
    MS-Off Ver
    Excel 2007
    Posts
    2

    Modifying VB Code:Excell Macro and Visal Basic Programming

    Hello All.

    I am very new to using Excell Macros, infact just a few hours of use till now.I need a quick help on Macros.
    I have a formula in cell B4, which I would normally drag all the way to another cell,B14 .So I created the macro , by pushing the record Macro option. Here it is below.

    Sub Macro1()
    '
    ' Macro1 Macro
    '
    
    '
        Range("B4").Select
        Selection.AutoFill Destination:=Range("B4:B14"), Type:=xlFillDefault
        Range("B4:B14").Select
    End Sub
    Question : How can I change this script so that the Macro is executed from cell B4 to BX , the number X , would be decided by a value in cell B2. If the value is 10 ,
    then the macro should execute from "Cell:B4" till "Cell:Address of B4 + 10"
    Last edited by aero777; 08-27-2009 at 02:07 AM. Reason: Complying to Forum Rules

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Modifying VB Code:Excell Macro and Visal Basic Programming

    Without knowing the actual formula in B4 I would opt for something along the lines of:

    Sub Macro1()
    Cells(4,"B").Resize(1+Cells(2,"B")).FormulaR1C1 = Cells(4,"B").FormulaR1C1
    End Sub

  3. #3
    Registered User
    Join Date
    08-27-2009
    Location
    GR
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Modifying VB Code:Excell Macro and Visal Basic Programming

    Hello,

    Thank you for your reply....

    WoW!

    That works... Thank you again..

    Untill my next querry!
    My Best Regards,
    Aero777
    Last edited by aero777; 08-27-2009 at 06:57 AM.

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Modifying VB Code:Excell Macro and Visal Basic Programming

    re: the formula... INDEX should suffice and has the added advantage of being non-volatile unlike the existing formula

    =INDEX(A:A,ROWS($A$1:$A$4)+2*(ROWS($A$4:A4)-1))
    In code terms just apply the formula in one go (including B4 itself)

    Public Sub Example()
    Cells(4,"B").Resize(1+Cells(2,"B")).FormulaR1C1 = "=INDEX(C1,ROWS(R1C:R4C)+2*(ROWS(R4C:RC)-1))"
    End Sub
    Where B2 contains how many extra formulae are required in addition to that in B4.

+ 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