Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Little pete
 
Posts: n/a
Default change the code to be a formula

i have the following code added to the s/s tab which does what i want but is
there a way of adding this to cell like a formula thing like vlookup??

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Target.Column = 2 Then
If Target.Value = "" Then Exit Sub
Application.EnableEvents = False
Target.Value = Worksheets("Station").Range("A1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Station").Range("StationList"), 0), 0)
Application.EnableEvents = True
End If
End Sub

thanks pete
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default change the code to be a formula

First, your code actually changes the value of the cell after you type in your
data.

You won't be able to do that using a formula (well, unless you type the formula
in that cell).

You might be able to use a formula in an adjacent cell to return that same
value, though.

Something like this in C7:
=OFFSET(Station!A1,MATCH(B7,StationList,0),0)

If that doesn't work, you may want to post the address of StationList. It'll
make testing a bit easier.


Little pete wrote:

i have the following code added to the s/s tab which does what i want but is
there a way of adding this to cell like a formula thing like vlookup??

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Target.Column = 2 Then
If Target.Value = "" Then Exit Sub
Application.EnableEvents = False
Target.Value = Worksheets("Station").Range("A1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Station").Range("StationList"), 0), 0)
Application.EnableEvents = True
End If
End Sub

thanks pete


--

Dave Peterson
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
Formula for markup won't change when the initial value is changed. Steve in Eugene Excel Worksheet Functions 3 November 10th 05 06:41 PM
I Need a formula to evaluate a cell with + or - values Bob in Oklahoma Excel Worksheet Functions 6 October 31st 05 02:41 PM
Change formula for Employee Shift Schedule template Pam Soreide Excel Worksheet Functions 1 September 7th 05 03:10 AM
formula / code help needed Paul Watkins Excel Discussion (Misc queries) 2 March 16th 05 08:27 PM
Is it possible to change the "result of a formula" to a "number? Renee R. Excel Discussion (Misc queries) 0 February 8th 05 02:27 PM


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