Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default initial value in a cell with validation

Hello,

I use several cells with the same validation fields. Is it possible to
create a macro that sets the initial value of a cell with validation?

Bernd

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default initial value in a cell with validation

Bernd,

I am assuming you are using a List type Validation. Use code like the
following:

Sub AAA()
Dim S As String
S = Mid(Range("A1").Validation.Formula1, 2)
Range("A1").Value = Range(S)(1, 1)
End Sub

Change the "A1" to your cell reference.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"bernd" wrote in message
oups.com...
Hello,

I use several cells with the same validation fields. Is it possible to
create a macro that sets the initial value of a cell with validation?

Bernd


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default initial value in a cell with validation

This works, but now I want to repeat this macro for all cells with in
column J. (starting from row 5).
I edited your code, but it doesn't work. What am I doing wrong?

Sub initial_value()
Dim S As String
Dim vCell As Range
For i = 5 To 65
vCell = Cells(i, 10)
S = Mid(Range(vCell).Validation.Formula1, 2)
Range(vCell).Value = Range(S)(1, 2)
Next i
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default initial value in a cell with validation

You Dimmed vCell As Range and then used Range(vCell), in other words the
Range of a Range, and it blows up. Take a look at this code:

Sub initial_value()
Dim S As String
Dim vCell As Range
Dim i As Integer
For i = 5 To 65
Set vCell = Cells(i, 10)
S = Mid(vCell.Validation.Formula1, 2)
vCell.Value = Range(S)(1, 1)
Next i
End Sub

You had also changed the line:
vCell.Value = Range(S)(1, 1)
to read
vCell.Value = Range(S)(1, 2)

That would have pointed the vCell Value to the first row, second column, of
the validation list. Is there a second column? If not, then you would have
returned nothing.

Mike F

"bernd" wrote in message
oups.com...
This works, but now I want to repeat this macro for all cells with in
column J. (starting from row 5).
I edited your code, but it doesn't work. What am I doing wrong?

Sub initial_value()
Dim S As String
Dim vCell As Range
For i = 5 To 65
vCell = Cells(i, 10)
S = Mid(Range(vCell).Validation.Formula1, 2)
Range(vCell).Value = Range(S)(1, 2)
Next i
End Sub



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default initial value in a cell with validation

Thanks for the explanation. The code works fine now.



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
how to keep the first initial of a name &delete the rest in cell mark Excel Discussion (Misc queries) 2 February 28th 07 05:35 PM
How can I have an initial zero in an Excel cell? ALupin Excel Discussion (Misc queries) 4 November 11th 06 10:16 AM
? sort data in a drop down box w/ initial cell entry Leef Excel Worksheet Functions 1 June 3rd 06 01:56 AM
Run Macro after initial cell edit? mrpunkin Excel Programming 5 July 2nd 05 12:35 AM
Perform oiperations relative to initial selected cell scratching my head Excel Discussion (Misc queries) 1 May 30th 05 05:42 PM


All times are GMT +1. The time now is 01:06 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"