Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 594
Default VLOOKUP/Validation box macro

Hi all......

Is it possible to create some sort of macro that will detect if a 1 is
entered in A1 and thereby cause A2 to have a VLOOKUP formula set in it, and
if a 2 is entered in A1 to have a Dropdown Validation box appear in A2
instead of the VLOOKUP formula, and back and forth......and if nothing, or
anything else is entered in A1, then A2 will remain blank..........

TIA
Vaya con Dios,
Chuck, CABGx3



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 473
Default VLOOKUP/Validation box macro

Clr wrote:
Is it possible to create some sort of macro that will detect if a 1 is
entered in A1 and thereby cause A2 to have a VLOOKUP formula set in it, and
if a 2 is entered in A1 to have a Dropdown Validation box appear in A2
instead of the VLOOKUP formula, and back and forth......and if nothing, or
anything else is entered in A1, then A2 will remain blank..........


Yes.
In the module belonging to the worksheet something like this:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Intersect(Me.Range("A1"), Target) Is Nothing Then Exit Sub
Me.Range("A2").Clear
If TypeName(Me.Range("A1").Value)="Double" Then
Select Case Me.Range("A1")
Case 1:
Me.Range("A2").Formula = "=VLOOKUP(...)"
Case 2:
Me.Range("A2").Validation.Add xlValidateWholeNumber
End Select
End If
End Sub

Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - reply in newsgroup

  #3   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 594
Default VLOOKUP/Validation box macro

Thanks Bill......

I'm by no means a programmer and was scared when I first saw your code, but
it was clear enough that I eventually was able to tune it to do exactly what
I wanted in my situation..........here's my result, based on your
response.....it works super.......

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Intersect(Me.Range("A1"), Target) Is Nothing Then Exit Sub
Me.Range("A2").Clear
If TypeName(Me.Range("A1").Value) = "Double" Then
Select Case Me.Range("A1")
Case 1:
Me.Range("A2").Formula = "=vlookup(c1,mytable,2,false)"
Case 2:
'Me.Range ("A2")
Range("a2").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:=xlBetween, Formula1:="=$K$1:$K$5"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
'xlValidateWholeNumber
End Select
End If
End Sub

Thanks muchly again,.....just one more question, is there any way to modify
the code so the trigger entries in A1 could be some text instead of just a 1
and 2?

Vaya con Dios,
Chuck, CABGx3





"Bill Manville" wrote in message
...
Clr wrote:
Is it possible to create some sort of macro that will detect if a 1 is
entered in A1 and thereby cause A2 to have a VLOOKUP formula set in it,

and
if a 2 is entered in A1 to have a Dropdown Validation box appear in A2
instead of the VLOOKUP formula, and back and forth......and if nothing,

or
anything else is entered in A1, then A2 will remain blank..........


Yes.
In the module belonging to the worksheet something like this:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Intersect(Me.Range("A1"), Target) Is Nothing Then Exit Sub
Me.Range("A2").Clear
If TypeName(Me.Range("A1").Value)="Double" Then
Select Case Me.Range("A1")
Case 1:
Me.Range("A2").Formula = "=VLOOKUP(...)"
Case 2:
Me.Range("A2").Validation.Add xlValidateWholeNumber
End Select
End If
End Sub

Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - reply in newsgroup



  #4   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 594
Default VLOOKUP/Validation box macro

Thanks anyway, but I was able to finally figure it out myself as to how to
make "text" do the triggering.......

Vaya con Dios,
Chuck, CABGx3


"CLR" wrote in message
...
Thanks Bill......

I'm by no means a programmer and was scared when I first saw your code,

but
it was clear enough that I eventually was able to tune it to do exactly

what
I wanted in my situation..........here's my result, based on your
response.....it works super.......

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Intersect(Me.Range("A1"), Target) Is Nothing Then Exit Sub
Me.Range("A2").Clear
If TypeName(Me.Range("A1").Value) = "Double" Then
Select Case Me.Range("A1")
Case 1:
Me.Range("A2").Formula = "=vlookup(c1,mytable,2,false)"
Case 2:
'Me.Range ("A2")
Range("a2").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:=xlBetween, Formula1:="=$K$1:$K$5"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
'xlValidateWholeNumber
End Select
End If
End Sub

Thanks muchly again,.....just one more question, is there any way to

modify
the code so the trigger entries in A1 could be some text instead of just a

1
and 2?

Vaya con Dios,
Chuck, CABGx3





"Bill Manville" wrote in message
...
Clr wrote:
Is it possible to create some sort of macro that will detect if a 1 is
entered in A1 and thereby cause A2 to have a VLOOKUP formula set in

it,
and
if a 2 is entered in A1 to have a Dropdown Validation box appear in A2
instead of the VLOOKUP formula, and back and forth......and if

nothing,
or
anything else is entered in A1, then A2 will remain blank..........


Yes.
In the module belonging to the worksheet something like this:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Intersect(Me.Range("A1"), Target) Is Nothing Then Exit Sub
Me.Range("A2").Clear
If TypeName(Me.Range("A1").Value)="Double" Then
Select Case Me.Range("A1")
Case 1:
Me.Range("A2").Formula = "=VLOOKUP(...)"
Case 2:
Me.Range("A2").Validation.Add xlValidateWholeNumber
End Select
End If
End Sub

Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - reply in newsgroup





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
Using Vlookup with validation Brian Excel Worksheet Functions 4 May 4th 23 03:43 AM
Data Validation, VLookup or If ??????? dragons_lair Excel Discussion (Misc queries) 3 May 27th 09 09:02 AM
Data Validation-VLOOKUP Leaflet Excel Discussion (Misc queries) 1 February 18th 09 03:14 PM
data validation using vlookup cbra Excel Worksheet Functions 5 October 26th 05 12:24 PM
vlookup with validation table jparker Excel Discussion (Misc queries) 3 August 12th 05 02:12 AM


All times are GMT +1. The time now is 01:16 AM.

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"