Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default Having a formula reference a a range

I am trying to get a vlookup formula to reference a range name. The code is
below - I know it's gotta be possible, but I can't get it to work!
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 11/12/2004 by
'
Dim shtdate As String
Range("c1").Select
Range("c1").Activate
shtdate = InputBox("Enter date of sheet to reference")
ActiveCell = shtdate


Range("B7").Select
ActiveCell = "=VLOOKUP($A7,shtdate!$A$3:$C$97,2,FALSE)"


End Sub


Any help would be greatly appreciated.
Thanks - Paula
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Having a formula reference a a range

Paula,

Try this:

ActiveCell.Formula = "=VLOOKUP($A7," & shtdate & "!$A$3:$C$97,2,FALSE)"

hth,

Doug Glancy

"Paula" wrote in message
...
I am trying to get a vlookup formula to reference a range name. The code
is
below - I know it's gotta be possible, but I can't get it to work!
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 11/12/2004 by
'
Dim shtdate As String
Range("c1").Select
Range("c1").Activate
shtdate = InputBox("Enter date of sheet to reference")
ActiveCell = shtdate


Range("B7").Select
ActiveCell = "=VLOOKUP($A7,shtdate!$A$3:$C$97,2,FALSE)"


End Sub


Any help would be greatly appreciated.
Thanks - Paula



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 618
Default Having a formula reference a a range

Hi

my problem with this is that sheet names can't contain / so if the person
enters
1/1/05 in response to this question:
shtdate = InputBox("Enter date of sheet to reference")
you'll have a problem.

maybe putting an example of how you want the data entered (or a default
value) might be useful?
e.g.
shtdate = Inputbox("Enter date of sheet to reference, e.g. 010105")
or
shtdate = Inputbox("Enter date of sheet to reference","Sheet Date","010105")

Cheeers
JulieD

"Doug Glancy" wrote in message
...
Paula,

Try this:

ActiveCell.Formula = "=VLOOKUP($A7," & shtdate & "!$A$3:$C$97,2,FALSE)"

hth,

Doug Glancy

"Paula" wrote in message
...
I am trying to get a vlookup formula to reference a range name. The code
is
below - I know it's gotta be possible, but I can't get it to work!
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 11/12/2004 by
'
Dim shtdate As String
Range("c1").Select
Range("c1").Activate
shtdate = InputBox("Enter date of sheet to reference")
ActiveCell = shtdate


Range("B7").Select
ActiveCell = "=VLOOKUP($A7,shtdate!$A$3:$C$97,2,FALSE)"


End Sub


Any help would be greatly appreciated.
Thanks - Paula





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Having a formula reference a a range

A template is good, but it's much more friendly to let the user input
the date any way s/he wants, and have VBA do the work:

Public Sub Enter_Formula_In_B7()
Const sDATE_FORMAT = "dd MMM yyyy"
Const sTWO_LINES As String = vbNewLine & vbNewLine
Const sMSG1 As String = "Enter date of sheet to reference:"
Const sMSG2 As String = "Reference must be a date!" & sTWO_LINES
Const sMSG3 As String = "Sheet '%%' does not exist!" & sTWO_LINES
Const sFORMULA As String = _
"=VLOOKUP($A7,'%%'!$A$3:$C$97,2,FALSE)"
Const sTITLE As String = "Enter Formula"
Const nSTRING_TYPE As Long = 2
Dim vInput As Variant
Dim wsRef As Worksheet
Dim sDefault As String
Dim sMsg As String
Dim sDate As String

sMsg = sMSG1
sDefault = Format(Date, sDATE_FORMAT)
Do
vInput = Application.InputBox( _
Prompt:=sMsg, _
Title:=sTITLE, _
Default:=sDefault, _
Type:=nSTRING_TYPE)
If vInput = False Then Exit Sub 'User cancelled
If IsDate(vInput) Then
sDate = Format(vInput, sDATE_FORMAT)
On Error Resume Next
Set wsRef = Sheets(sDate)
On Error GoTo 0
If wsRef Is Nothing Then sMsg = _
Application.Substitute(sMSG3, "%%", sDate) & sMSG1
Else
sMsg = sMSG2 & sMSG1
End If
Loop Until Not wsRef Is Nothing
Range("B7").Formula = _
Application.Substitute(sFORMULA, "%%", sDate)
End Sub

Change the format (sDATE_FORMAT) as desired...


In article ,
"JulieD" wrote:

my problem with this is that sheet names can't contain / so if the person
enters
1/1/05 in response to this question:
shtdate = InputBox("Enter date of sheet to reference")
you'll have a problem.

maybe putting an example of how you want the data entered (or a default
value) might be useful?
e.g.
shtdate = Inputbox("Enter date of sheet to reference, e.g. 010105")
or
shtdate = Inputbox("Enter date of sheet to reference","Sheet Date","010105")

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
Relative Range Reference in a sumifs formula cbotos Excel Worksheet Functions 6 April 1st 10 02:59 AM
Cell reference in formula as range tjfwestcoast Excel Discussion (Misc queries) 4 February 3rd 10 06:39 PM
Formula to return the reference of a range of cells tiptoe Excel Discussion (Misc queries) 4 February 16th 08 11:28 PM
using a dummy cell to reference a range into a formula talderman Excel Discussion (Misc queries) 1 June 29th 06 09:09 PM
Reference range in formula problem crapit Excel Programming 4 July 3rd 04 07:26 PM


All times are GMT +1. The time now is 03:34 PM.

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"