Results 1 to 2 of 2

Thread: using excel in vb

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    146

    using excel in vb

    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

  2. #2
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: using excel in vb

    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:
    1. Sub Macro2()
    2.     Rows("5:5").Select
    3.     Selection.Insert Shift:=xlDown
    4.     Range("A2:A5").Select
    5.     Range("A5").Activate
    6.     ActiveCell.FormulaR1C1 = "=SUM(R[-3]C:R[-1]C)"
    7.     Columns("D:G").Select
    8.     Selection.EntireColumn.Hidden = True
    9. 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width