Dropdown List Add New Feature Needed
paste this code to a new module. The test procedure passes a range object to
the AddNewLine procedure
Option Explicit
Sub TEST()
AddNewLine Worksheets("Sheet1").Range("MyData")
ActivateRange Worksheets("Sheet1").Range("MyData")
End Sub
Sub AddNewLine(target As Range)
Dim bAvailable As Boolean
Dim cell As Range
Dim rName As String
bAvailable = True
'check space below is not used
With target
For Each cell In .Offset(.Rows.Count).Resize(2).Cells
If Not IsEmpty(cell) Then
bAvailable = False
Exit For
End If
Next
If bAvailable Then
.Rows(.Rows.Count).Copy
rName = .Name.Name
With .Resize(.Rows.Count + 1)
'.Rows(.Rows.Count).Copy
.Rows(.Rows.Count).PasteSpecial xlADORecordset
.Name = rName
.Rows(.Rows.Count).ClearContents ' omit if you need
formula
End With
Else
MsgBox "No room below table to textend it"
End If
End With
End Sub
Sub ActivateRange(target As Range)
With target
.Parent.Activate
.Cells(.Rows.Count, 1).Select
End With
End Sub
you can replicate this several ways.
one would be to have a cell on a sheet with a button next to it. the button
would have a macro assigned to it like:
sub ButtonClick()
AddNewLine Range( Range("A1") )
End sub
where cell A1 holds the name of the range you want to add to,
This isn't complete - but if its the right direction, then we're getting
somewhere.
_____________________
Hi folks.
How can I create a button or list entry that takes the user to a cell to
add a "new item" or "new user" to a dropdown list array by way of row
insertion and cursor placement... that takes the last entry in the
existing drop down list to use as an "add new" "button" or trigger?
The event is to add a new row to an existing named array, which
automatically updates all code in the workbook, if the row is inserted
from within the existing array.
So the last entry in the drop down list array could (would) be an "Add
New" selection for the user to choose. When the fill is performed, the
action could be to test that cell content and act accordingly. The user
would get switched to the array with the cursor in the left most cell of
the newly inserted row. This also has the effect of keeping the cell
formatting as well for solid color arrays, that is.
Is this possible? I suppose a test loop that tests the cell content,or
one that tests for and grabs the content even before it makes it to a
cell. Anyway, when one selects the add new selection from the drop down
list, instead of filling that data into the cell, it performs the insert
and pop over function so that a new record can be added.
I have a sheet that has about eight small,named arrays on it and use it
as a master data sheet for a 'presentation' type sheet that draws much of
its data from lookups to the array sheet.
A simple row insertion on that sheet updates all arrays, etc. in the
entire workbook. Nice job, guys. I LIKE IT!
So, anyway, is this a good approach for expanding the contents of an
array? Is keeping all these arrays on a single sheet a good approach?
This is like yet another new form of a database configuration, in the
final analysis. Thanks for any thoughts or views.
At least one inquiring mind wants to know.
|