Results 1 to 4 of 4

Thread: Help with Excel VB Script

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    1

    Help with Excel VB Script

    Hi there,

    I must say that I am completely VB illiterate and hence need some help with the following.

    I am trying to create a bill of costs spreadsheet in Excel which I have successfully completed. I want to add the option of increasing a line at the bottom (between the final line and the Total Sum).

    I was able to create a macro to add the line but had difficulty with making Excel always add the line to the bottom of the list as the list always gets bigger and hence the last line is always updated.

    Does this make sense? Can anyone help with writing some simple script?

    Thanks,
    Petes

    PS. Attached is a sample file.
    Attached Files Attached Files

  2. #2
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    Re: Help with Excel VB Script

    You mean make it for free.....

    Well.....




    Like this......(Lucky sun off a .....)
    Last edited by Dnereb; Apr 23rd, 2007 at 04:05 AM.
    why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
    for every question you ask provide an answer on another thread.

  3. #3
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: Help with Excel VB Script

    I couldn't view Dnereb's code, so I don't know if this is any different...

    This is not the most elegant solution, but it's reliable and simple. I'm assuming you're not going to run into 100s of lines, otherwise performance may be an issue.
    VB Code:
    1. Private Function FindLastLine() As Long
    2.     Dim r As Long
    3.     r = 7
    4.     With ActiveSheet
    5.         While .Cells(r, 1).Text <> ""
    6.             r = r + 1
    7.         Wend
    8.     End With
    9.     FindLastLine = r
    10. End Function
    11.  
    12. Sub AddRow2()
    13.     Dim r As Long
    14.     r = FindLastLine
    15.     Rows(r - 1).Select
    16.     Selection.Insert shift:=xlDown
    17.     Cells(r - 1, 1).Formula = r - 7
    18.     Cells(r, 1).Formula = r - 6
    19. End Sub
    This world is not my home. I'm just passing through.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Help with Excel VB Script

    Excel VBA question moved to Office Development.

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