+ Reply to Thread
Results 1 to 1 of 1

Adding rows depending on user input

Hybrid View

  1. #1
    Registered User
    Join Date
    10-31-2008
    Location
    asia
    Posts
    32

    Adding rows depending on user input

    Hello Again,

    Ok, I think I found a code onnline which does a large portion of what I want it to do except a few things. I'll give you the code here and explain the changes that are needed. Once again thank you for your time.

    Sub InsertRowsAndFillFormulas_caller()
      '-- this macro shows on Tools, Macro..., Macros (Alt+F8) dialog
      Call InsertRowsAndFillFormulas
    End Sub
    Sub InsertRowsAndFillFormulas(Optional vRows As Long = 0)
    ' Documented:  http://www.mvps.org/dmcritchie/excel/insrtrow.htm
    ' Re: Insert Rows --   1997/09/24 Mark Hill <markhill@charm.net.noSpam>
       ' row selection based on active cell -- rev. 2000-09-02 David McRitchie
       Dim x As Long
       ActiveCell.EntireRow.Select  'So you do not have to preselect entire row
       If vRows = 0 Then
        vRows = Application.InputBox(prompt:= _
          "How many rows do you want to add?", Title:="Add Rows", _
          Default:=1, Type:=1) 'Default for 1 row, type 1 is number
        If vRows = False Then Exit Sub
       End If
    
       'if you just want to add cells and not entire rows
       'then delete ".EntireRow" in the following line
    
       'rev. 2001-01-17 Gary L. Brown, programming, Grouped sheets
       Dim sht As Worksheet, shts() As String, i As Long
       ReDim shts(1 To Worksheets.Application.ActiveWorkbook. _
           Windows(1).SelectedSheets.Count)
       i = 0
       For Each sht In _
           Application.ActiveWorkbook.Windows(1).SelectedSheets
        Sheets(sht.Name).Select
        i = i + 1
        shts(i) = sht.Name
    
        x = Sheets(sht.Name).UsedRange.Rows.Count 'lastcell fixup
    
        Selection.Resize(rowsize:=2).Rows(2).EntireRow. _
         Resize(rowsize:=vRows).Insert Shift:=xlDown
    
        Selection.AutoFill Selection.Resize( _
         rowsize:=vRows + 1), xlFillDefault
    
        On Error Resume Next    'to handle no constants in range -- John McKee 2000/02/01
        ' to remove the non-formulas -- 1998/03/11 Bill Manville
        Selection.Offset(1).Resize(vRows).EntireRow. _
         SpecialCells(xlConstants).ClearContents
       Next sht
       Worksheets(shts).Select
    End Sub
    My Tabels columns are from B to G. Here is the calculations and refrences for Each Column assuming the user fills in all the input cells (F10-F14):

    column B
    row 73: =IF(E73=""," ",VLOOKUP(E73, $H$7:$J$25, 3, FALSE))
    row 74: =IF(E74=""," ",VLOOKUP(E74, $H$7:$J$25, 3, FALSE))
    ...
    row 84: =IF(E84=""," ",VLOOKUP(E84, $H$7:$J$25, 3, FALSE))

    column C

    row 73: =IF(E70=""," ",VLOOKUP(E70, $H$7:$K$25, 2, FALSE))
    ....
    ...
    row 84: =IF(E84=""," ",VLOOKUP(E84, $H$7:$K$25, 2, FALSE))

    column D
    row 70: =IF(E70=""," ",VLOOKUP(E70, $H$7:$K$25, 4, FALSE))
    row 71:=IF(E71=""," ",VLOOKUP(E71, $H$7:$K$25, 4, FALSE))
    row 72:=IF(E72=""," ",VLOOKUP(E72, $H$7:$K$25, 4, FALSE))
    row 73:=IF(E73=""," ",VLOOKUP(E73, $H$7:$L$25, 5, FALSE))
    row 74:=IF(E74=""," ",VLOOKUP(E74, $H$7:$L$25, 5, FALSE))
    row 75:=IF(E75=""," ",VLOOKUP(E75, $H$7:$L$25, 5, FALSE))
    row 76:=IF(E76=""," ",VLOOKUP(E76, $H$7:$M$25, 6, FALSE))
    row 77:=IF(E77=""," ",VLOOKUP(E77, $H$7:$M$25, 6, FALSE))
    row 78:=IF(E78=""," ",VLOOKUP(E78, $H$7:$M$25, 6, FALSE))
    row 79:=IF(E79=""," ",VLOOKUP(E79, $H$7:$N$25, 7, FALSE))
    row 80:=IF(E80=""," ",VLOOKUP(E80, $H$7:$N$25, 7, FALSE))
    row 81:=IF(E81=""," ",VLOOKUP(E81, $H$7:$N$25, 7, FALSE))
    row 82:=IF(E82=""," ",VLOOKUP(E82, $H$7:$O$25, 8, FALSE))
    row 83:=IF(E83=""," ",VLOOKUP(E83, $H$7:$O$25, 8, FALSE))
    row 84:=IF(E84=""," ",VLOOKUP(E84, $H$7:$O$25, 8, FALSE))

    Column E

    row 70:=IF(ISNA(VLOOKUP("yes_1",$A$32:$G$50,7,FALSE)), "", VLOOKUP("yes_1",$A$32:$G$50,7,FALSE))
    row 71:=IF(ISNA(VLOOKUP("yes_2",$A$32:$G$50,7,FALSE)), "", VLOOKUP("yes_2",$A$32:$G$50,7,FALSE))
    row 72:=IF(ISNA(VLOOKUP("yes_3",$A$32:$G$50,7,FALSE)), "", VLOOKUP("yes_3",$A$32:$G$50,7,FALSE))
    row 73:=IF(ISNA(VLOOKUP("yes_1",$B$32:$G$50,6,FALSE)), "", VLOOKUP("yes_1",$B$32:$G$50,6,FALSE))
    row 74:=IF(ISNA(VLOOKUP("yes_2",$B$32:$G$50,6,FALSE)), "", VLOOKUP("yes_2",$B$32:$G$50,6,FALSE))
    row 75:=IF(ISNA(VLOOKUP("yes_3",$B$32:$G$50,6,FALSE)), "", VLOOKUP("yes_3",$B$32:$G$50,6,FALSE))
    row 76:=IF(ISNA(VLOOKUP("yes_1",$C$32:$G$50,5,FALSE)), "", VLOOKUP("yes_1",$C$32:$G$50,5,FALSE))
    row 77:=IF(ISNA(VLOOKUP("yes_2",$C$32:$G$50,5,FALSE)), "", VLOOKUP("yes_2",$C$32:$G$50,5,FALSE))
    row 78:=IF(ISNA(VLOOKUP("yes_3",$C$32:$G$50,5,FALSE)), "", VLOOKUP("yes_3",$C$32:$G$50,5,FALSE))
    row 79:=IF(ISNA(VLOOKUP("yes_1",$D$32:$G$50,4,FALSE)), "", VLOOKUP("yes_1",$D$32:$G$50,4,FALSE))
    row 80:=IF(ISNA(VLOOKUP("yes_2",$D$32:$G$50,4,FALSE)), "", VLOOKUP("yes_2",$D$32:$G$50,4,FALSE))
    row 81:=IF(ISNA(VLOOKUP("yes_3",$D$32:$G$50,4,FALSE)), "", VLOOKUP("yes_3",$D$32:$G$50,4,FALSE))
    row 82:=IF(ISNA(VLOOKUP("yes_1",$E$32:$G$50,3,FALSE)), "", VLOOKUP("yes_1",$E$32:$G$50,3,FALSE))
    row 83:=IF(ISNA(VLOOKUP("yes_2",$E$32:$G$50,3,FALSE)), "", VLOOKUP("yes_2",$E$32:$G$50,3,FALSE))
    row 84:=IF(ISNA(VLOOKUP("yes_3",$E$32:$G$50,3,FALSE)), "", VLOOKUP("yes_3",$E$32:$G$50,3,FALSE))

    Column F
    row 70: Empty
    row 71:=IF(E10="","",E10)
    row 72:Empty
    row 73:=IF(E11="","",E11)
    row 74:Empty
    row 75:=IF(E12="","",E12)
    row 76:Empty
    row 77:=IF(E13="","",E13)
    row 78:Empty
    row 79:=IF(E14="","",E14)
    row 80:Empty
    row 81:=IF(E15="","",E15)
    row 82:Empty
    row 83:=IF(E15="","",E15)
    row 84:Empty

    Column G
    row 70: Empty
    row 71: =F10
    row 72:Empty
    row 73:Empty
    row 74:=F11
    row 75:Empty
    row 76:Empty
    row 77:=F12
    row 78:Empty
    row 79:Empty
    row 80:=F13
    row 81:Empty
    row 82:Empty
    row 83:=F14
    row 84:Empty


    Changes needed to be made to the code:

    1- If the user types anything at cell F11(probably use ISTEXT(if true add 3 rows <73:75>) function). If F12 Also has Text, add 3 rows 76:78. Do the same until F14. As soon as F13, for example, is empty no need to check other cells, the user inputs data starting from F10 working his way down (no skipping of cells).

    Thank you for your time and effort.
    Last edited by VBA Noob; 11-10-2008 at 09:08 AM. Reason: Added code tags as per forum rules

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1