PDA

View Full Version : Solved: VBA Help Plz



ranuse
10-24-2010, 01:49 PM
Hi,

I'm trying to write some code that will do the following:
1. Select the last column that contains data in a worksheet
2. Inserts a blank column to the left of the selected column
3. Enter specified text to the first row of the new column (e.g., "Cost + Tax")
4. Sum entries in existing columns whose 1st row label is "Cost" and "Tax" and store result in the below the new column "Cost + Tax"

Any help would be much appreciated.
Thanks for you time .

mdmackillop
10-24-2010, 02:42 PM
Welcome to VBAX
Try this
Option Explicit

Sub test()
Dim c As Range
Dim Cost As Long, Tax As Long
Dim Rws As Long
Dim Col As Long

Set c = Cells.Find("*", Cells(1, 1), , , xlByColumns, xlPrevious)
Col = c.Column
c.EntireColumn.Insert
Cells(1, Col) = "Cost + Tax"
Cost = Rows(1).Find("Cost").Column
Tax = Rows(1).Find("Tax").Column
Rws = ActiveSheet.UsedRange.Rows.Count
Range(Cells(2, Col), Cells(Rws, Col)).FormulaR1C1 = "=RC" & Cost & "+RC" & Tax
End Sub

ranuse
10-24-2010, 02:49 PM
It works great! Thank you very much for your help and time.