how do i write in Macro/VBA that column H = Column G-F for the current region?

Posted on 2011-04-27
Last Modified: 2012-05-11
i wrote a script in macro which entering values to columns G and F and now how do i write macro that column H will be the subscration of column F minus G?

Question by:gvilbis
    LVL 23

    Assisted Solution

    Sorry not sure exactly what you are after. Could you supply an example file to give us a better idea of what you need

    LVL 5

    Accepted Solution

    The below code uses the last row of g and fills colum H with the formula:

    Sub test()
    Dim wks As Worksheet
    Dim LastRow As Integer
    Set wks = ActiveWorkbook.Sheets("Sheet1")
    With wks
        LastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
        .Range("H1:H" & LastRow).Formula = "=RC[-2]-RC[-1]"
    End With
    End Sub

    Open in new window


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
    This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
    The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
    The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now