Excel to Access strings as numbers - excel

Not sure if this can be done through Access or some simple code in Excel? But say I have in Excel a few rows like so:
CARD TRIGGER CATEGORY QUANTITY TARGET
Magma Drake StartOfTurn Damage 1 Opponent
Lava Moat ReciveDamage Damage 5 AttackingCards
Rockslide AfterCasting Damage 15 AllOpponentCards
Ash Imp AfterCasting Damage 5 TargetOpponentCard
Eruption AfterCasting Damage 15 TargetOpponentCard
Eruption AfterCasting Damage 15 Opponent
Lava Streams StartOfTurn Mana 2 OwnerMana
Firebomb Troll Death Damage 8 AllOpponentCards
Scorched Avata AfterCasting Damage 8 Opponent
Scorched Avata AfterCasting Damage 8 Owner
Hero of Flame AfterCasting Stats 3 AllOwnersCards
Falling Stars AfterCasting DamagePlus 8 Opponent
Falling Stars AfterCasting DamagePlusPercent 4 AllOpponentCards
I want to be able to export this to Access, but instead of strings for the TRIGGER, CATEGORY and TARGET, I want to use numbers. Thus:
StartOfTurn = 1
ReciveDamage = 2
AfterCasting = 3
Death = 4
ect... for all 3 columns. I was not sure if I could put in an alias value for strings and then export the alias value? How can I do this? Also note I would like to keep the string values in Excel as its easier for me to understand, but its easier for code if the values in Access are numbers.

One approach might be:
Create "lookup" tables (say, named Triggers, Cateogories, and Targets) in Access that list the numbers that correspond to the strings.
Import or link your existing Excel data into a "staging" table in Access.
Write a query in Access that joins the staging table to the lookup tables to "look up" the numbers based on the strings.
Use the query directly, or run a make table query or an append query based on it to transfer the results to a separate table and use that table instead.

The easiest thing would be to export the whole table into Access and then run an Update query in Access to replace the values you want replaced. So far as I know, you can't update values only on export, you would have to first replace them in Excel which you said you don't want to do.
Also, for the record, it would be very easy to keep this all in Access if you used dropdowns (aka Combo boxes) to choose your values. You could display the full string, but only store the number in the table.

Not sure i used the best approach, but i created a lookup table like Brian said, but in excel. So i had something like
B1 B2
triggers triggers_numbers
startofturn 1
endofturn 5
endofturn 5
Afterattack 4
startofturn 1
Then when i imported the data to access, i used the values in trigger_numbers instead of triggers.

Related

Group Shared Expense Calculator using Excel

I want to track the expenses of me and my friends with excel. I have the following table structure:
Date
Amount
Paid By
Split Type
Name 1
Name 2
Name 3
...
16.05.
4.99$
Name 1
Split Equal
...
16.05.
10$
Name 1
Split Unequal by Percentage
50%
50%
...
18.05.
10$
Name 3
Split Unequal by Amount
2$
6$
2$
...
The goal is, to create a matrix-like table where you can easily read which person owes another. By using a simple excel table with big, nested formulas & try and error I was able to successfully accomplish this. However, I'm curious whether this would be doable using Pivot Tables, since they are very powerful and I always feel like "they can do everything" (and the formulas are neither nice nor easy to maintain in the future).
So for the above example, the desired result could look like this (I guess the way you get there should be pretty obvious):
Name 1
Name 2
Name 3
Name 1
-
-
0.34$
Name 2
6.66$
-
6$
Name 3
-
-
-
Question
So in short, my question is: Is there a way of creating the second table based on the first one (and maybe additional "helper" tables) using Excel's Pivot funcitonality? I would be really happy to get answers / tips for this. It would also be sufficient if you show me one case (i.e., split unequal by amount) and I'll implement the other cases based on that.
What I've tried so far
As already stated above, using a plain table I was already able to solve this task. However, the solution doesn't seem to be very elegant and thus I tried to accomplish it with by using a Pivot Table. I created one but I already struggle to get the same names in the rows & columns. If I get this working somehow, the next step would be to compute the correct values in the cells (I assume by introducing a new measure and a DAX-Formula, but I have no idea how :D)
Thanks for your help and feel free if you need more information!
Edit 1: Clarify the Result Matrix
As Jos stated, the result matrix maybe isn't that obvious unlike I throught, so I'd like to give one example:
Name 1 owes Name 3 0.34$ - why?
Name 1 pays 4.99$ and this should be split equally (thus in particular name 3 owes name 1 1.66$.
Name 1 pays 10$, however this doesn't account to name 3 since only name 1 and name 2 have to share this money
Name 3 pays 10$ from which name 1 ones him 2$, name 2 6$ and name 3 2$.
In sum, name 3 owes name 1 1.33$ from the first payment, and name 1 owes name 3 2$ from the third payment. This can be summarized by: name 3 owes name 1 1.66 $ - 2$ = -0.33$ (which is the same as saying name 1 owes name 3 0.33$

Compare and Sort a Column in Excel

I am a firefighter and when we have large wildfires in California we order a lot of overhead positions to assist at the fire. These overhead position fall into 1 of 6 categories.
As I import the list of outstanding overhead requests into Excel, is there I way I can assign a value to each position? 1 through 6? I can then sort the entire list by number and hand a list of all "1's" to one person and "2's" to another person etc.
I'd like to assign a value to each position COMPARED to a master list. On the master list I will tell Excel that a "Helicopter Coordinator" = 1 for example.
Thanks for the assistance :)
Here's an example of some miscellaneous overhead positions:
O-42 OPERATIONS BRANCH DIRECTOR (OPBD)
O-44 TECHNICAL SPECIALIST - CREWS (CALIFORNIA ONLY)
O-45 INCINET STATUS/CHECK-IN RECORDER (CALIFORNIA ONLY)
O-47 OPERATIONS BRANCH DIRECTOR (OPBD)
O-48 FIRE FIGHTER TYPE 2 (FFT2)
O-50 HELICOPTER COORDINATOR (HLCO)
O-52 MEDICAL UNIT LEADER (MEDL)

Generating a unique identifier list with multiple tables & criteria

I'm not a coder, just someone who uses excel for basic estimating functions at work. However I've found myself in need of a complex list or index system.
Background/Intent: (Skip below if doesn't matter.) In an apartment building construction they build buildings like opened books - mirror images of 2 bed 2 bath apartments, for example. There is a standard "typical" unit and then the mirror image across the hall, the "reverse" unit. The door swings are all opposite from one to the other. My job is to figure out how to give each door a unique identifier code based on: Bldg No., Unit Type, Door No., Door Swing (left or right.) The raw data tables are provided below.
I've attempted to clean this up as much as possible, but there are two steps (I think) to this process.
Step 1:
The raw data table is on the left. My output field is on the right. I want to be able to select a drag down box, like data validation list, and select the building. Then a formula (which one?) spits out a list of every unit type per building. For example, Bldg 5 has 2 each of "A1 Typ." How do I get the formula to recognize that if there are 2 of them, to produce 2 separate lines for "A1 Typ." And so on and so forth until all 41 occurences/units have been accounted for and labeled appropriately. Some occur once, some multiple times, and some zero.
Step 1
From there, Step 2.
I want to use this output field again to automate another sequence, this time pulling from a different table, see picture. Now, depending on the unit type under the "type" column, I want it to expand each unit type showing each indivudual door number (1,2,3 etc through 12) and if it's an L (LH) or R (RH), and if there is more than one, to list out each occurence. (what formula?)
Then the decriptor text that will pop up under "DOOR LABEL" column would just be a joining of several fields to give a unique identifier. (suggestions?)
Step 2.
Easy right? Is this too much for excel, or can this be done?
Thanks so much for considering helping me out!

Combine data from two sheets to form conglomerated output (similar to database outer join)

Suppose I have an Excel workbook (.xlsx / .xlsm) with the following two sheets (simplified for example's sake):
Sheet 1:
Student_Id: Name: Age: Sex: ...
1 Bobby 10 Male ...
2 Suzy 11 Female ...
3 Mike 10 Male ...
4 Sally 9 Female ...
....
Sheet 2:
Class: Student_Id:
Math 1
Math 2
Math 4
English 3
English 4
....
Now, I would like to create an output sheet which is a mixture of the two, looking something along the lines of:
Output:
Class: Name: Age: Sex: ...
Math Bobby 10 Male ...
Math Suzy 11 Female ...
Math Sally 9 Female ...
English Mike 10 Male ...
English Sally 9 Female ...
....
Now, I know this is fairly easy to do using VLOOKUPs and INDEX, MATCH functions and I've already done that, but my question is whether there's a better feature existing in Excel to accomplish this.
I'm thinking of just using ADO to query the two sheets and output it, but I'm just feeling convinced there has to be a better way / built in feature.
Extra notes:
My data doesn't need to be live - meaning that it doesn't need to be formulas that will slow down Excel - which I know I can do with Copy / Paste Special, Values.
I know of Power Query, but I'm trying not to use something that will require my users to install an add-in (but macros within the workbook would be ok).
This is easily done with a built-in feature of Excel. It is called Microsoft Query.
It can be found on the Ribbon under Data - Other Sources - From Microsoft Query.
You select your workbook from the ancient looking dialog (it can be the same workbook).
It will complain that it cannot find any tables, Click OK. And then from the dialog go into Options and check the box for System Tables. You will now be able to select the columns you want from your two source tables. You can join them in the query builder like this:
Now select Return Data to Microsoft Excel from the File menu.
An Import Data dialog will display allowing you to select where you want the new table of data to appear.
You can even set properties to refresh periodically, if you want.
Note: this solution requires no VBA and no worksheet formulas. It produces a joined table based on the SQL you create in Microsoft Query (which is a built-in component of Excel). The resulting table can be static or dynamic.

Excel: How to parse/cast text as a formula?

Is it possible to parse/cast text (like "=A1+A2") as a formula in MS Excel? I want to build a formula from pieces of text - some of which will only be typed in later by a user.
If the INDIRECT() function did not only work for referencing cells, then I could have typed this =INDIRECT("=A1+A2").
I know you can a work around this problem by simply adding a lot more hidden columns to do sub calculations. But for the sake scalability and efficiency, I would rather do something like the above.
I found a similar questions here and here, yet they don't solve my problem.
The Real-world problem:
Read on for a better understanding as to why you would want to do the above
Scenario
Each item in the list consists of a string, which contains anywhere from 1 to 5 account names each. Each account name is followed by an account number in brackets. The length of the number determines the type of account. Part of the account number is a date, of which the date format depends on the type of account. Further more, each account type may have more that 1 account-number length associated with it, although each number-length[*] is only associated with 1 account type.
Objectives
Extract account-names and their respective account-numbers and account-types from a list.
Make an assumption as to the account-type from the account-number
Validate this assumption by inspecting the build of the number and elements in the name
Check the validity of the account-numbers depending on their type.
The tricky part (this is where my problem lies)
The account-types and their respective account-number-lengths are not known before hand, and are typed into a table by the user of the sheet, specifying a type of account and the number-lengths associated with this account-type. The user should type this into a list - not go and tinker around with delicate formulas
Done so far
Column A: Contains the raw data (each cell has up to 5 names and numbers)
Columns B..F: Each column extracts 1 name, remains empty if all are already extracted
Columns G..K: Each column extracts 1 number corresponding to its name in columns B..F, remains empty if all are already extracted
Columns L..P: Each column calculates the length of the corresponding number in columns
G..K
Now the user would type the following details into a table which assigns certain number-lengths an account type:
TYPE2, BUSINESS, (OR(length=13,length=6))
where length will later be replaced with the cell address which contains the calculated account number-length.
What I want to do now
Columns Q..U:
Should all indicate the account-type of the corresponding account-number in columns G..K. The idea is to build a nested if-elseIf-elseIf formula using the criteria typed in by the user as specified above. Example of one of the elseIF statements:
SUBSTITUTE(CONCATENATE("=IF(",criteria,",",type,",",errCode)),"length","O10"))
All of these elseIf statements will then be concatenated together to form a master formula which will then need to be parsed/cast as a formula to calculate the account-type
This proposal uses only 5 columns (1 for each account-number, containing the master formula) and a table specifying account-types and criteria, also keeping the user away from formulas. Editing 1 line of code (the criteria) will update all formulas. Efficient & Scalable.
Since the user should never tinker around with the formulas under the hood, a simple 1 column if-elseIf-elseIf is out of the question. The alternative to the above would be to make a separate column to test for each account-type for each account-number. Separating/Abstracting out each test to its own column results in much better readability, easier editing & much less debugging - Unless you like multi-screen-wide-formulas. Example: 5 account-numbers * 10 possible account types = 50 extra columns.
Each edit to any criteria needs to copied to 4 other non-adjacent columns and drag-filled down 10,000 rows (columns can not be adjacent since it is effectively a 5x5 array of columns). Not Efficient nor scalable. Unless I'm missing some elegant way of updating non-adjacent formulas in a single click
The rest of the validations error indications are trivial.
Sample data
Tshepo Trust (6901/2005) Marlene Mead (8602250646085)
Great Force Inv 67 Pty Ltd (200602258007)
Jane (870811) Livingstone (6901/2005) Janette Appel (8503250647056) James (900111)
I know all this would probably be much easier to achieve with clever usage of VBA, eliminating all the need to simulate abstraction, encapsulation, multi-dimensional arrays and functional programming on a spreadsheet. But until I can program in VBA, worksheet formulas will be my refuge.
[*]: account number-length could also be described as the amount of digits in the number or as indicated by this formula: LEN(accNumber)
In VBA you have access to Cell.Formula.
I usually used Range to peek a cell by address.
I'm not sure if this would answer your question(it's a very detailed question!), but if your user was entering the account numbers in a table (I'm calling it 'RefTable') , that was:
Length of account number | business type
----------------------------------------
6 | Accountant
8 | Advisor
Then you could just use a vlookup on the length of the account number, given you've already separated them out.
=vlookup(len(accNumber), Reftable, 2, false)
Make sure that you either use a dynamic range name, or specify plenty of space below in RefTable, so that when your users add types, they don't get lost.
Also, if you have two different accounts with the same length, this could get you into trouble.

Resources