LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Use VBA to reset data validation (=list) value to first value in that list (list is a named range)

My final solution was to give up on my existing code, and add a
commandbutton to the sheet- I linked the update throught that commandbutton,
and now everything works as desired (because I eliminated the need to re-set
the combobox value to the first value in the named range list)
Thanks,
Keith

"ker_01" wrote in message
...
Another possible issue (possibly only because of my lack of understanding
about the parameters); on any given day, the list shows today +14 days.
When the macros run, they update the source range for that cell, but the
existing value may be yesterday's date (or earlier) and not a valid value.

I've been assuming that Range(S)(1) will return the first value from the
source list, and that the current selection in that cell (an old date that
no longer meets the validation criteria) cannot be selected.

Still don't have it working, so any additional advice on what to
troubleshoot would be very much appreciated.

Thanks,
Keith

"ker_01" wrote in message
...

I get a 1004 runtime error, method 'range' of object '_worksheet' failed.

I also tried S(1) instead of Range(S)(1) but got a runtime error 13 type
mismatch

Sheet12.Range("E2").Validation.Formula1 = "=DatesForSelection14Days"

The source list is a list of dates, where the first item in that list is
today's date, then tomorrows, then the next day (etc). I have code that
updates that list so that when raw data is loaded, the list of dates is
updated to start with "todays" date. So for example, the first item in
the list today is '10/21/2008'

So, looking at the code I think I just figured something out (maybe the
problem, or maybe just something I don't understand): In the following
code, S evaluates to S = "=DatesForSelection14Days" which is a string,
not a range/array. I don't get any autotext options behind "Formula1"
but now I'm thinking that maybe Range(S)(1) doesn't recognize this as a
named range?

Thank you for any additional help,
Keith

If Target.Address = "$B$2" Then 'dept changed
'graph updates are handled with dynamic named ranges
'just reset the date back to earliest date possible
S = Sheet12.Range("E2").Validation.Formula1
Sheet12.Activate
Sheet12.Range("E2").Value = Range (S)(1)
Set Target = Sheet12.Range("$E$2")
End If


"Bob Phillips" wrote in message
...
That works fine for me.

What error do you get?

--
__________________________________
HTH

Bob

"ker_01" wrote in message
...
I have a cell that has data validation (=list), populated by a named
range

In my VBA, I need to be able to reset that list to the first value in
the list. I had the code working, but I must have tweaked something
without knowing it, and now it doesn't work anymore.

If Target.Address = "$B$2" Then
'just reset the date back to earliest date in the list
S = Sheet12.Range("E2").Validation.Formula1
Sheet12.Activate
Sheet12.Range("E2").Value = Range(S)(1) '<- this is the line that
doesn't work
Set Target = Sheet12.Range("E2")
End If

Thanks for any advice,
Keith









 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Validation List from a Dynamic Named Range on Another Workshe Jeremy Excel Worksheet Functions 5 March 29th 10 09:26 AM
Finding first value in named range referred to in data validation list ker_01 Excel Programming 2 October 4th 08 04:52 AM
Remove empty cells from named list / validation list Sp00k Excel Worksheet Functions 4 April 28th 06 03:45 PM
Dynamic Named Range inside a Data Validation list ? Richard[_34_] Excel Programming 5 March 11th 06 01:58 PM
Using a data validation list to look up a defined named range in another worksheet Laura Hunt Charts and Charting in Excel 0 November 24th 05 02:29 PM


All times are GMT +1. The time now is 08:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"