Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Insert columns and values programmatically with IF statement
I'm trying to perform the following with the least amount of code.
1) Test the value of "x" and if TRUE, do the following ... 2) On Sheet1, select column B and insert 4 columns to the right 3) On Sheet1, enter the following text values: B1 = "SUM" C1 = "PRODUCT" D1 = "QUOTIENT" E1 = "SUMPRODUCT" 4) On Sheet1, enter the following formulas: B2 =SUM(1,1) C2 =PRODUCT(1,1) D2 =QUOTIENT(1,1) E2 =SUMPRODUCT(1,1) With Sheet1 If x = "SUM" Then Columns($B:$B).Select Selection.Insert Shift:=xlToRight Selection.Insert Shift:=xlToRight Selection.Insert Shift:=xlToRight Selection.Insert Shift:=xlToRight Range("B1").Select ActiveCell.FormulaR1C1 = "SUM" Range("C1").Select ActiveCell.FormulaR1C1 = "PRODUCT" Range("C1").Select ActiveCell.FormulaR1C1 = "QUOTIENT" Range("D1").Select ActiveCell.FormulaR1C1 = "SUMPRODUCT" Range("B2").Select ActiveCell.FormulaR1C1 = "=SUM(1,1)" Range("C2").Select ActiveCell.FormulaR1C1 = "=PRODUCT(1,1)" Range("D2").Select ActiveCell.FormulaR1C1 = "=QUOTIENT(1,1)" Range("E2").Select ActiveCell.FormulaR1C1 = "=SUMPRODUCT(1,1)" Else End With Is there any way to do this with less code ? - Ronald K. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
HOW-TO: programmatically create SAS length statement | Excel Discussion (Misc queries) | |||
OR Exact statement not working to compare values in two columns | Excel Worksheet Functions | |||
Can I set Insert Options programmatically? | Excel Programming | |||
Insert Textbox values to seperate rows/columns | Excel Programming | |||
Macro to insert page breaks when values in 1 or more columns changes | Excel Programming |