473,394 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Nested IF Excel problem

63
I have a problem in Excel 2000. I am trying to return a value in Column F based on what is Column E. There are about 14 different text variants in Column E (all look like "2008H1", "2008H2)). Depending on the variable in column E I want a different columns value (eg column P, S, T etc) returning in Column F for that row.

The nested IF function didn't work as I was limited to 7 variants. I tried doing something called criteria - which would allow me to add in two criteria - but I didn't really know what I was doing! (code below)

ActiveWorkbook.Names.Add Name:="Criteria1", RefersToR1C1:="=IF('Shelf Allocations'!E2="2008H2",P2,IF('Shelf Allocations'!E2="2009H1",S2,IF('Shelf Allocations'!E2="2009H2",V2,IF('Shelf Allocations'!E2="2010H1",Y2,IF('Shelf Allocations'!E2="2010H2",AB2,IF('Shelf Allocations'!E2="2011H1",AE2,IF('Shelf Allocations'!E2="2011H2",AH2,IF('Shelf Allocations'!E2="2012H1",AK2))))))))"

ActiveWorkbook.Names.Add Name:="Criteria2", RefersToR1C1:="=IF(E2='2012H2',AN2,IF(E2='2013H1', AQ2,IF(E2='2013H2',AT2,IF(E2='2014H1',AW2,IF(E2='2 014H2',AZ2,IF(E2='2015H1',BC2,IF(E2='2015H2',BF2,I F(E2='2015H2',BI2))))))))"

ActiveCell.FormulaR1C1 = "=IF(Criteria1,Criteria1,Criteria2)"

This didn't work either.

I also tried creating a look up in column F that looked up value E against a look up table like the one below:

2008H1 =P2
2008H2 =S2

I tried to get the macro to paste the =P2 bit into column F - but it only recognised it as text and not a formula - so this didn't work either.

any ideas please I'm going mad!!!!!
Oct 21 '08 #1
1 1381
The following uses the "Switch" function. There are other ways to do this.
'--
Sub TheOneIWant()
ActiveSheet.Range("F1").Formula = MatchThis(ActiveSheet.Range("E2").Value)
End Sub

Function MatchThis(ByRef E2Value As String) As String
MatchThis = Switch(E2Value = "2009H1", "=S2", _
E2Value = "2009H2", "=V2", E2Value = "20010H1", "=Y2")
End Function
Oct 21 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: moller | last post by:
I'm new to perl but not to programming in general. I hav been trying to put some data into an excel sheet. And it works fine.... if I hardcode the data. And I of cource I dont want to do that....
1
by: moller | last post by:
I'm reposting this under a more appropriate subject since excel really has nothing to do with my problem. I'm new to perl but not to programming in general. I have been trying to put some...
3
by: Erik Bongers | last post by:
Hi, Nested classes only seem to be able to access static members of the surrounding class : class SurroundingClass { public: class InnerClass { public:
1
by: NA | last post by:
Is it possible to have adjustable tables (not Access tables per se) but those in Ms Word or Excel based on nexted forms three deep? In other words, if I have a main form, Repair History, both the...
10
by: nimmi_srivastav | last post by:
Below you will see an example of a nested conditional expression that this colleague of mine loves. He claims that it is more efficient that a multi-level if-else-if structure. Moreover, our...
8
by: Robert W. | last post by:
I've almost completed building a Model-View-Controller but have run into a snag. When an event is fired on a form control I want to automatically updated the "connnected" property in the Model. ...
1
PrinsonG
by: PrinsonG | last post by:
My Query is How do I export to excel/csv using Nested Repeaters. My project is web-based and i am using C#.Net. In this i use three repeaters. one displays ID, Name of the user. second...
0
by: JRough | last post by:
Hi, I have a page with a form that is included into a php page. It has some php variables which are headers based on the user choices. In the form I will send some mysql data columns but right...
5
by: ElPresidente | last post by:
Now that I have your attention haha... I have this weekly file that contains several hundred invoices that need to be given batch letters in according to the following hierarchy. Employee...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.