i am opening a text file in excel using vb and i want to sum up 2 or some times 3 cell is it possible to insert a blank row where i can insert the sum of those cells .
also how can i hide some of the columns programatically
Printable View
i am opening a text file in excel using vb and i want to sum up 2 or some times 3 cell is it possible to insert a blank row where i can insert the sum of those cells .
also how can i hide some of the columns programatically
Others may be able to address your specific questions. I just want to offer a general tip. You can often use the macro function of excel to find out what you need o do. Pull up a spreadsheet, click Tools => Macro ==> record new macro (call it whatever you want). Then preform the actions you want your program to do. The Click stop recording. The click Tools ==> Macro ==> Visual Basic Editor. In the modules folder of the macro you created will be the VBA code of the actions you Performed. This can often just be turned into VB code. Here an example using your post:
VB Code:
Sub Macro2() Rows("5:5").Select Selection.Insert Shift:=xlDown Range("A2:A5").Select Range("A5").Activate ActiveCell.FormulaR1C1 = "=SUM(R[-3]C:R[-1]C)" Columns("D:G").Select Selection.EntireColumn.Hidden = True End Sub
Here is a link to the FAQ here that may also be of interest to you:
http://www.vbforums.com/showthread.php?t=391665