+ Reply to Thread
Results 1 to 9 of 9

Form Created - VBA Dropdown Doesnt Work When The Rows Are Hidden?

Hybrid View

  1. #1
    Registered User
    Join Date
    09-23-2015
    Location
    UK
    MS-Off Ver
    2010
    Posts
    68

    Form Created - VBA Dropdown Doesnt Work When The Rows Are Hidden?

    Hi,

    I have created a "form" where you can put information into a number of fields, hit a "Submit" button and the information stacks up as a list below this form, I use the following code and works fine -

    Sub SUBMIT()
    Dim NextRow As Long
    Application.ScreenUpdating = False
    NextRow = Sheets(1).Cells(Rows.Count, "C").End(xlUp).Row + 1
    NextRow = Sheets(1).Cells(Rows.Count, "F").End(xlUp).Row + 1
    NextRow = Sheets(1).Cells(Rows.Count, "G").End(xlUp).Row + 1
    NextRow = Sheets(1).Cells(Rows.Count, "H").End(xlUp).Row + 1
    NextRow = Sheets(1).Cells(Rows.Count, "J").End(xlUp).Row + 1
    NextRow = Sheets(1).Cells(Rows.Count, "K").End(xlUp).Row + 1
    NextRow = Sheets(1).Cells(Rows.Count, "M").End(xlUp).Row + 1
    NextRow = Sheets(1).Cells(Rows.Count, "O").End(xlUp).Row + 1
    If NextRow < 37 Then
    NextRow = 37
    End If
    Sheets(1).Cells(NextRow, "C") = Sheets(1).Range("J9:O9").Value
    Sheets(1).Cells(NextRow, "F") = Sheets(1).Range("J11:O11").Value
    Sheets(1).Cells(NextRow, "G") = Sheets(1).Range("J13:O13").Value
    Sheets(1).Cells(NextRow, "H") = Sheets(1).Range("J15:K15").Value
    Sheets(1).Cells(NextRow, "J") = Sheets(1).Range("M15").Value
    Sheets(1).Cells(NextRow, "K") = Sheets(1).Range("O15").Value
    Sheets(1).Cells(NextRow, "M") = Sheets(1).Range("J17:O17").Value
    Sheets(1).Cells(NextRow, "O") = Sheets(1).Range("C20:O26").Value
    Sheets(1).Range("J9:O9").ClearContents
    Sheets(1).Range("J11:O11").ClearContents
    Sheets(1).Range("J13:O13").ClearContents
    Sheets(1).Range("J15:K15").ClearContents
    Sheets(1).Range("M15").ClearContents
    Sheets(1).Range("O15").ClearContents
    Sheets(1).Range("J17:O17").ClearContents
    Sheets(1).Range("C20:O26").ClearContents
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    MsgBox "Submitted"
    ActiveWorkbook.Save
    End Sub
    The list it stacks into I want to hide, however when I hide the rows where the list is, the 'stacking' doesnt seem to work anymore and only puts the information into row 37 each time and overwrites itself?

    Any ideas?

    Thanks
    Last edited by npsnps; 06-02-2016 at 09:38 AM.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Form Created - VBA Dropdown Doesnt Work When The Rows Are Hidden?

    Assuming that they're merged cells, try this:

    Sub SUBMIT() 'npsnps
    Dim NextRow As Long, Col As String, Rng As String
     
    Col = "C": Rng = "J9": GoSub GetNext
    Col = "F": Rng = "J11": GoSub GetNext
    Col = "G": Rng = "J13": GoSub GetNext
    Col = "H": Rng = "J15": GoSub GetNext
    Col = "J": Rng = "M15": GoSub GetNext
    Col = "K": Rng = "O15": GoSub GetNext
    Col = "M": Rng = "J17": GoSub GetNext
    Col = "O": Rng = "C20": GoSub GetNext
    
    MsgBox "Submitted"
    ActiveWorkbook.Save
                        Exit Sub
    GetNext:
    NextRow = Application.MAX(37, Sheets(1).Cells(Rows.count, Col).End(xlUp).Row + 1)
    Sheets(1).Cells(NextRow, Col) = Sheets(1).Range(Rng).Value
    Sheets(1).Range(Rng).ClearContents
    Return
    End Sub
    Last edited by xladept; 06-02-2016 at 10:24 AM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    09-23-2015
    Location
    UK
    MS-Off Ver
    2010
    Posts
    68

    Re: Form Created - VBA Dropdown Doesnt Work When The Rows Are Hidden?

    Apologies, Ive managed to make it move all boxes but the same problem occurs, fine when unhidden, overwrites row when hidden?

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Form Created - VBA Dropdown Doesnt Work When The Rows Are Hidden?

    Uno Mas:

    Sub SUBMIT() 'npsnps
    Dim NextRow As Long, Col As String, Rng As String
     
    Col = "C": Rng = "J9": GoSub GetNext
    Col = "F": Rng = "J11": GoSub GetNext
    Col = "G": Rng = "J13": GoSub GetNext
    Col = "H": Rng = "J15": GoSub GetNext
    Col = "J": Rng = "M15": GoSub GetNext
    Col = "K": Rng = "O15": GoSub GetNext
    Col = "M": Rng = "J17": GoSub GetNext
    Col = "O": Rng = "C20": GoSub GetNext
    
    MsgBox "Submitted"
    ActiveWorkbook.Save
                        Exit Sub
    GetNext: NextRow = 37
                With Sheets(1)
    Do Until .Cells(NextRow, Col) = "": NextRow = NextRow + 1: Loop
    .Cells(NextRow, Col) = .Range(Rng).Value
    .Range(Rng).Value = ""
                End With: Return
    End Sub

  5. #5
    Registered User
    Join Date
    09-23-2015
    Location
    UK
    MS-Off Ver
    2010
    Posts
    68

    Re: Form Created - VBA Dropdown Doesnt Work When The Rows Are Hidden?

    Thank you for the information but I cant seem to make this one work, it only moves the first box down (J9:O9) ?

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Form Created - VBA Dropdown Doesnt Work When The Rows Are Hidden?

    Try this:

    Sub SUBMIT() 'npsnps
    Dim NextRow As Long, Col As String, Rng As String
     
    Col = "C": Rng = "J9": GoSub GetNext
    Col = "F": Rng = "J11": GoSub GetNext
    Col = "G": Rng = "J13": GoSub GetNext
    Col = "H": Rng = "J15": GoSub GetNext
    Col = "J": Rng = "M15": GoSub GetNext
    Col = "K": Rng = "O15": GoSub GetNext
    Col = "M": Rng = "J17": GoSub GetNext
    Col = "O": Rng = "C20": GoSub GetNext
    
    MsgBox "Submitted"
    ActiveWorkbook.Save
                        Exit Sub
    GetNext: NextRow = 37
                With Sheets(1)
    Do Until .Cells(NextRow, Col) = "": NextRow = NextRow + 1: Loop
    .Cells(NextRow, Col) = .Range(Rng).Value
    .Range(Rng).ClearContents
                End With: Return
    End Sub
    Last edited by xladept; 06-07-2016 at 11:26 AM.

  7. #7
    Registered User
    Join Date
    09-23-2015
    Location
    UK
    MS-Off Ver
    2010
    Posts
    68

    Re: Form Created - VBA Dropdown Doesnt Work When The Rows Are Hidden?

    Comes up with the error - Run-time error 1004, cannot change part of a merged cell.

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Form Created - VBA Dropdown Doesnt Work When The Rows Are Hidden?

    You're welcome and thanks for the rep!

  9. #9
    Registered User
    Join Date
    09-23-2015
    Location
    UK
    MS-Off Ver
    2010
    Posts
    68

    Re: Form Created - VBA Dropdown Doesnt Work When The Rows Are Hidden?

    Works beautifully, thank you for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] HLOOKUP doesnt work in all rows
    By Immortal2014 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-20-2015, 04:58 PM
  2. [SOLVED] Freeze columns and rows doesnt seem to work
    By colwise in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 07-21-2015, 11:15 PM
  3. Click events on buttons created at runtime only work on the last button created
    By Treacle in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-25-2010, 05:44 AM
  4. Rows(i).Hidden = True doesn't work
    By Evil Red Smurf in forum Excel General
    Replies: 3
    Last Post: 06-22-2009, 06:26 AM
  5. In Word 2007, how do I work within a form created in Word 2003
    By LilyMarie in forum Word Formatting & General
    Replies: 1
    Last Post: 03-05-2009, 04:26 AM
  6. [SOLVED] Doesn't work as it SHOULD .. Rows.Hidden /with SpecialCells
    By Gunnar Johansson in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-01-2006, 06:25 AM
  7. [SOLVED] =ROW-1, =SUBTOTAL(3,$B$2:$B2) don't work in hidden rows.
    By StargateFan in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-25-2006, 03:10 PM

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