Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to set a specific value into a data validated cell using macro

HI

I have a couple of range names ProductQuantity and ProductColor (A15:A12000
and C15:12000 respectively), ProductColor are data valitaded cells with a
list of colors, I want that after entering a value to ProductQuantity the
corresponding row of ProductColor shows the first value of the list.

I belive a have to use Worksheet_Change event but how to get/set the value
on a datalist cell ?

Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default How to set a specific value into a data validated cell using macro

Lets assume that the validation list for column C is H1 thru H3 (containing
the colors: red, green, blue). Then:

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Set a = Range("A15:A12000")
If Intersect(t, a) Is Nothing Then Exit Sub
Application.EnableEvents = False
t.Offset(0, 2).Value = Range("H1").Value
Application.EnableEvents = True
End Sub

--
Gary''s Student - gsnu200858


"DimensionAV" wrote:

HI

I have a couple of range names ProductQuantity and ProductColor (A15:A12000
and C15:12000 respectively), ProductColor are data valitaded cells with a
list of colors, I want that after entering a value to ProductQuantity the
corresponding row of ProductColor shows the first value of the list.

I belive a have to use Worksheet_Change event but how to get/set the value
on a datalist cell ?

Thanks in advance.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default How to set a specific value into a data validated cell using macro

Here is a slightly different approach...

Private Sub Worksheet_Change(ByVal Target As Range)
Dim R As Range
Set R = Intersect(Target.EntireRow, Range("ProductColor"))
If Not R Is Nothing And Target.Column < Range("ProductColor").Column Then
Application.EnableEvents = False
R.Value = Range(Mid(R.Validation.Formula1, 2))(1).Value
Application.EnableEvents = True
End If
End Sub

This event code doesn't use any hard-coded ranges. Besides using the named
range for the ProductColor column, it also let's VB get the validation list
of the Target's row. This way, if there are different validation lists in
effect for different sections of the ProductColor range, the correct "first
item" in that particular validation list will be returned. Doing this is
probably over-kill as one would expect only one validation list to be in
effect for the entire range... but, then, who knows.

--
Rick (MVP - Excel)


"Gary''s Student" wrote in message
...
Lets assume that the validation list for column C is H1 thru H3
(containing
the colors: red, green, blue). Then:

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Set a = Range("A15:A12000")
If Intersect(t, a) Is Nothing Then Exit Sub
Application.EnableEvents = False
t.Offset(0, 2).Value = Range("H1").Value
Application.EnableEvents = True
End Sub

--
Gary''s Student - gsnu200858


"DimensionAV" wrote:

HI

I have a couple of range names ProductQuantity and ProductColor
(A15:A12000
and C15:12000 respectively), ProductColor are data valitaded cells with a
list of colors, I want that after entering a value to ProductQuantity the
corresponding row of ProductColor shows the first value of the list.

I belive a have to use Worksheet_Change event but how to get/set the
value
on a datalist cell ?

Thanks in advance.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to set a specific value into a data validated cell using m

HI Gary

Considering that I have different sets of Colors (In the Colors Sheet), I
use the following formula to define which is element that corresponds to it:

=OFFSET(INDIRECT(SUBSTITUTE($G15,"
","")),0,0,COUNTA(INDIRECT(SUBSTITUTE($G15," ","")&"_Col")),1)

That formula is taken from the following example to make dynamic lists:
http://www.contextures.com/xlDataVal02.html


Would be possible to reproduce that formula in a VB macro or do you think
that there is a better approach to it ?


Thanks.

"Gary''s Student" wrote:

Lets assume that the validation list for column C is H1 thru H3 (containing
the colors: red, green, blue). Then:

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Set a = Range("A15:A12000")
If Intersect(t, a) Is Nothing Then Exit Sub
Application.EnableEvents = False
t.Offset(0, 2).Value = Range("H1").Value
Application.EnableEvents = True
End Sub

--
Gary''s Student - gsnu200858


"DimensionAV" wrote:

HI

I have a couple of range names ProductQuantity and ProductColor (A15:A12000
and C15:12000 respectively), ProductColor are data valitaded cells with a
list of colors, I want that after entering a value to ProductQuantity the
corresponding row of ProductColor shows the first value of the list.

I belive a have to use Worksheet_Change event but how to get/set the value
on a datalist cell ?

Thanks in advance.

Reply
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 Validated Cell Arrow not Appearing Varne Excel Discussion (Misc queries) 9 January 2nd 08 05:51 PM
cell data not validated if navigating cell to cell with mouse LoveThatMouse Excel Worksheet Functions 6 May 21st 06 09:03 PM
Selecting a specific cell (that is data validated) cliodne[_13_] Excel Programming 2 April 23rd 06 07:55 AM
be validated or not validated in a cell x taol Excel Programming 1 November 22nd 05 01:36 AM
Using macro to add data in specific cell within a table The Grinch[_3_] Excel Programming 0 July 14th 04 10:59 AM


All times are GMT +1. The time now is 12:00 PM.

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

About Us

"It's about Microsoft Excel"