Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default i to = column in Formula

How do I get i to show in the formula as column 1, then 2 then 3 etc. for the five drop downs in A to E? Once the i is inside the formula " "'s it is just a plain letter i.

Sub FiveDD()

Dim i As Long
Range("A1").Select
For i = 1 To 5
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=OFFSET($A$2,0,0,COUNTA($A$2:$A$200),1) "
.IgnoreBlank = True
.InCellDropdown = True
.ShowInput = True
.ShowError = True
ActiveCell.Offset(0, 1).Select
End With
Next
End Sub

Thanks.
Howard
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default i to = column in Formula

Hi Howard,

Am Tue, 15 Apr 2014 21:33:56 -0700 (PDT) schrieb L. Howard:

How do I get i to show in the formula as column 1, then 2 then 3 etc. for the five drop downs in A to E? Once the i is inside the formula " "'s it is just a plain letter i.


if your columns have the same number of values and you don't have to
COUNTIF for each column this is all you need:

With Range("A1:E1")
With .Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:= _
xlBetween,
Formula1:="=OFFSET($A$2,0,Column()-1,COUNTA($A$2:$A$200))"
.IgnoreBlank = True
.InCellDropdown = True
.ShowInput = True
.ShowError = True
End With
End With


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default i to = column in Formula




if your columns have the same number of values and you don't have to

COUNTIF for each column this is all you need:



With Range("A1:E1")

With .Validation

.Delete

.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,

Operator:= _

xlBetween,

Formula1:="=OFFSET($A$2,0,Column()-1,COUNTA($A$2:$A$200))"

.IgnoreBlank = True

.InCellDropdown = True

.ShowInput = True

.ShowError = True

End With

End With


Regards

Claus B.

--


Another clever little gem.

Thanks Claus.

Howard
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default i to = column in Formula



if your columns have the same number of values and you don't have to

COUNTIF for each column this is all you need:



With Range("A1:E1")

With .Validation

.Delete

.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,

Operator:= _

xlBetween,

Formula1:="=OFFSET($A$2,0,Column()-1,COUNTA($A$2:$A$200))"

.IgnoreBlank = True

.InCellDropdown = True

.ShowInput = True

.ShowError = True

End With

End With





Regards

Claus B.

--


Another clever little gem, thanks Claus.

Howard
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default i to = column in Formula

Howard,
It appears that you are trying to use dynamic lists without defining
the ranges with names. IMO, it's better to define the ranges as dynamic
and just use the names in the DV dialog. OR am I missing something
here?

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default i to = column in Formula

On Wednesday, April 16, 2014 7:14:42 AM UTC-7, GS wrote:
Howard,

It appears that you are trying to use dynamic lists without defining

the ranges with names. IMO, it's better to define the ranges as dynamic

and just use the names in the DV dialog. OR am I missing something

here?



--

Garry


You are correct, but how would I pass the named ranges to the desired column DV?

Howard
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default i to = column in Formula

On Wednesday, April 16, 2014 7:14:42 AM UTC-7, GS wrote:
Howard,

It appears that you are trying to use dynamic lists without defining

the ranges with names. IMO, it's better to define the ranges as
dynamic

and just use the names in the DV dialog. OR am I missing something

here?



--

Garry


You are correct, but how would I pass the named ranges to the desired
column DV?

Howard


Via the DV dialog? Or is there some reason you need to do this via
code?

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default i to = column in Formula

On Wednesday, April 16, 2014 8:43:29 AM UTC-7, GS wrote:
On Wednesday, April 16, 2014 7:14:42 AM UTC-7, GS wrote:


Howard,




It appears that you are trying to use dynamic lists without defining




the ranges with names. IMO, it's better to define the ranges as


dynamic




and just use the names in the DV dialog. OR am I missing something




here?








--




Garry






You are correct, but how would I pass the named ranges to the desired


column DV?




Howard




Via the DV dialog? Or is there some reason you need to do this via

code?



--

Garry


Yes, I wanted to use code to do something like this from Claus' suggestion.

With Range("A1:E1,G1,J1")
** seven +/- DV's **
End With

Where I was running a loop 5 times offsetting the DV code to each column.

Howard
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default i to = column in Formula

Yes, I wanted to use code to do something like this from Claus'
suggestion.

With Range("A1:E1,G1,J1")
** seven +/- DV's **
End With

Where I was running a loop 5 times offsetting the DV code to each
column


I see. The $ symbols need to be removed from the col labels, then, so
the formula adjusts accordingly. However, IMO, if you're designing a
solution worksheet I recommend defining those dynamic ranges and
manually 'construct' the DV lists so no code is required. If the
dynamic ranges are empty then so too will be the respective DV list.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default i to = column in Formula

Hi Howard,

Am Wed, 16 Apr 2014 09:14:58 -0700 (PDT) schrieb L. Howard:

Yes, I wanted to use code to do something like this from Claus' suggestion.


try:

Sub DropDowns()
Dim rngC As Range, myRng As Range
Dim myCnt As Long

With ActiveSheet
For Each rngC In .Range("A1:E1,G1,J1")
myCnt = WorksheetFunction.CountA(.Range(rngC, rngC.Offset(199)))
.Names.Add Name:="Col" & Chr(rngC.Column + 64), _
RefersTo:="=Offset(" & rngC.Address & ",1,," & myCnt & ")"
With rngC
With .Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:= _
xlBetween, Formula1:="=Col" & Chr(rngC.Column + 64)
.IgnoreBlank = True
.InCellDropdown = True
.ShowInput = True
.ShowError = True
End With
End With
Next
End With
End Sub


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional


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
Permanently link formula references to Column Names and not Column Cell Numbers Excel Dumbo Excel Discussion (Misc queries) 1 February 21st 13 03:23 AM
conditional formatting formula to highlight items on column B inrelation to column A hombreazul Excel Discussion (Misc queries) 4 March 4th 12 02:43 PM
A formula or macro that will place the date in an adjacent column Bany time something is typed in column A Mike C[_5_] Excel Programming 4 February 27th 08 01:57 AM
Copying a formula in a blank column as far as data in previous column basildon Excel Programming 1 December 16th 05 03:32 PM
Populating column N with a formula if column A is Null or Blank Steve Excel Programming 4 September 28th 04 01:50 PM


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