Solved

How to make data validation list drop-down appear in first column of new row in VBA?

Posted on 2014-02-25
3
279 Views
Last Modified: 2014-02-26
How do you set up the table and/or data validation list to be available on the first blank row of a table in VBA?

Thanks
0
Comment
Question by:mlagrange
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 39887763
An approach that worked for me:

1) Create your table

2) Resize your table so that it includes an empty row at the bottom

3) Add this code to the sheet module for the worksheet with the table, to force the table to resize with the extra blank row

Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim lo As ListObject
    Dim loRng As Range
    Dim loLastRow As Range
    
    Set lo = Me.ListObjects(1)
    Set loRng = lo.Range
    Set loLastRow = loRng.Rows(loRng.Rows.Count)
    
    If Not Intersect(loLastRow, Target) Is Nothing Then
        Application.EnableEvents = False
        lo.Resize loRng.Cells(1).Resize(loRng.Rows.Count + 1, loRng.Columns.Count)
        Application.EnableEvents = True
    End If
    
End Sub

Open in new window

0
 

Author Closing Comment

by:mlagrange
ID: 39888699
Thanks, Patrick!
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 39888800
You're most welcome :)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now