Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Worksheet Functions / May 2008

Tip: Looking for answers? Try searching our database.

NEED EQUATION PLEASE

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Carolan - 12 May 2008 16:24 GMT
Would like equation that says if A1 to A10 has 400 in it, the change 400 to
"James"
Could someone please help me.
Signature

Carolan

Gary''s Student - 12 May 2008 16:31 GMT
You might need a macro for this:

Sub crln()
Set rr = Range("A1:A10")
For Each r In rr
   If r.Value = 400 Then
       r.Value = "James"
   End If
Next
End Sub

Signature

Gary''s Student - gsnu200785

> Would like equation that says if A1 to A10 has 400 in it, the change 400 to
> "James"
> Could someone please help me.
Carolan - 12 May 2008 16:38 GMT
I'd rather do a formula if possible on a different sheet as I will have
several name.  For example, 400 = James, 401 - John, 402 = Kevin.  So there
could be all three numbers in a column.
Signature

Carolan

> You might need a macro for this:
>
[quoted text clipped - 10 lines]
> > "James"
> > Could someone please help me.
Max - 12 May 2008 16:49 GMT
Maybe something like this

Assume numbers in Sheet1, in A1 down
In Sheet2, place in A1
=IF(Sheet1!A1="","",VLOOKUP(Sheet1!A1,{400,"James";401,"John";402,"Kevin"},2,0))
Copy down
Signature

Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---

> I'd rather do a formula if possible on a different sheet as I will have
> several name.  For example, 400 = James, 401 - John, 402 = Kevin.  So there
> could be all three numbers in a column.
Carolan - 12 May 2008 17:33 GMT
Max, that works except what I'm trying to do is change the number in A1 to
the resulting text in the same cell.  In otherwords, if A1=400, change the
400 in A1 to "James"  So if I type 400 in A1 it will automatically change it
to "James" as soon as I move to the next cell.
Signature

Carolan

> Maybe something like this
>
[quoted text clipped - 5 lines]
> > several name.  For example, 400 = James, 401 - John, 402 = Kevin.  So there
> > could be all three numbers in a column.
David Biddulph - 12 May 2008 18:09 GMT
As stated earlier, that needs a macro, not a formula.
--
David Biddulph

> Max, that works except what I'm trying to do is change the number in A1 to
> the resulting text in the same cell.  In otherwords, if A1=400, change the
[quoted text clipped - 12 lines]
>> > there
>> > could be all three numbers in a column.
Ron Rosenfeld - 12 May 2008 18:15 GMT
>Max, that works except what I'm trying to do is change the number in A1 to
>the resulting text in the same cell.  In otherwords, if A1=400, change the
>400 in A1 to "James"  So if I type 400 in A1 it will automatically change it
>to "James" as soon as I move to the next cell.

As has been written, you cannot do that with a formula.  A formula can only
return a result to the cell in which it resides.  It cannot change another
cell, nor can it change itself, yet persist within the cell.

Take another look at Gary's student macro.

Or, if you want this automatically, use an event macro.

To enter this, right click on the sheet tab and select View Code from the
dropdown menu.  Then paste the code below into the window that opens.

=========================
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim a As Range
Dim c As Range
'set up to change entries in Column A only
Set a = Range("A:A")
If Not Intersect(Target, a) Is Nothing Then
   For Each c In Target
       Select Case c
           Case Is = 400
               c.Value = "James"
           Case Is = 401
               c.Value = "John"
           Case Is = 402
               c.Value = "Kevin"
       End Select
   Next c
End If
End Sub
=================================
--ron
Carolan - 13 May 2008 17:58 GMT
Thanks everyone - Ron's solution worked perfectly for my needs.
Signature

Carolan

> >Max, that works except what I'm trying to do is change the number in A1 to
> >the resulting text in the same cell.  In otherwords, if A1=400, change the
[quoted text clipped - 34 lines]
> =================================
> --ron
Gord Dibben - 13 May 2008 18:36 GMT
In addition to Ron's "worked perfectly" solution.

If your needs changed to many of these items, you can add to the "nums" and
"vals" arrays and not use the many "Case is" statements.

Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Range("A:A")  'adjust to suit
If Intersect(Target, r) Is Nothing Then
   Exit Sub
On Error GoTo endit:
Application.EnableEvents = False
End If
nums = Array(400, 401, 402, 403)  'adjust to suit
vals = Array("James", "Mike", "Harold", "Oscar")  'adjust to suit
For Each rr In r
   ival = 0
   For i = LBound(nums) To UBound(nums)
       If rr.Value = nums(i) Then
           ival = vals(i)
       End If
   Next
   If ival > 0 Then
   rr.Value = ival
   End If
Next
endit:
Application.EnableEvents = True
End Sub

Gord Dibben  MS Excel MVP

>Thanks everyone - Ron's solution worked perfectly for my needs.
Max - 12 May 2008 22:21 GMT
If you want to keep it simple, you could always copy the formula col at the
end of the day, then overwrite the source col with a paste special as values
Signature

Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---

> Max, that works except what I'm trying to do is change the number in A1 to
> the resulting text in the same cell.  In otherwords, if A1=400, change the
> 400 in A1 to "James"  So if I type 400 in A1 it will automatically change it
> to "James" as soon as I move to the next cell.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.