LibreOffice populating cells - spreadsheet

I have a spreadsheet containing data identifying the depot where a product is stored, the supplier of the product and the manufacturer of said product.
I wish to break this one spreadsheet into four .csv files and import csv files into an already created PostgreSQL db. Typically, depot.csv, product.csv, supplier.csv and manufacturer.csv.
depot.csv has <15 entries, supplier.csv & manufacturer.csv <350 entries each and product.csv < 2,000 entries.
Example of what I want to do.
I have created a list of unique depots in a worksheet called depot.
id name
paris
berlin
london
original spreadsheet data
id Depot depot_id PRODUCT NAME product_id SUPPLIED BY Manufacturer
1 Paris 1 Hand wipes Erenco Chem Group
6 London 3 Scrub Towels Chemicraft Chem Group
7 Berlin 2 WR2 Grease Greasy Bin Chem Group
the column depot_id is populated by using the following formula
=IF(B2=depot.$B$2,depot.$A$2, IF(B2=depot.$B$3,depot.$A$3, IF(B2=depot.$B$4,depot.$A$4, 9999)))
and a worksheet called depot
Now I need a formula to populate product_id but above formula is not sufficient.
Thanks.
Tommy.

This problem is probably best solved by using the vlookup function.

Okay it's working.
Formula looks like this... in cell C2 enter the following
=VLOOKUP(D2,Product.$A$2:$B4586,2,0)
explanation:
D2 = the text being searched for
Product.$A$2:$B$4586 = the search array, in another worksheet, being searched
2, = the value to be posted in cell C2. This is from the column B in the search array. The leftmost column should be the column containing the value searched for.
0 = signifies a unsorted/unordered list.
See http://forum.openoffice.org/en/forum/viewtopic.php?t=46746 for better explanation.
Also http://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_VLOOKUP_function
Thanks to Mauritz for reinforcing my research.
Tommy.

Related

VBA - Split, copy and paste characters from string into another cell (with conditions)

I'm at the beginning with VBA and struggling with a worksheet that need to be cleaned up.
I have a column with strings that mix zipcodes and city names. I want to extract from column A the zipcode and place in column B, and the city name with underscore in column C.
My (example) input:
A
55442
11211
1
12
11211_brooklyn
1002_new_york
new_york
brooklyn
What I want
A
55442
11211
1
12
11211_brooklyn
1002_new_york
new_york
brooklyn
B
55442
11211
1
12
11211
1002
C
brooklyn
new_york
new_york
brooklyn
I understand how to extract characters with the Left formula but it's not enough.
Any ideas?
Thanks.
B2:
=IF(ISNUMBER(A2),A2,IFERROR(1*LEFT(A2,FIND("_",A2)-1),""))
C2:
=MID(A2, 1+LEN(B2)+ISNUMBER(B2),99)
EDIT - As it appears that there are cases like 00010_alaska; zip codes that include leading zeros, this should be used instead for column C:
C2:
=IF(B2="",A2, IFERROR(MID(A2,1+FIND("_",A2),99),""))
in A column put your source list
in B column (zip code) put formula:
=IFERROR(NUMBERVALUE(TRIM(LEFT($A1,FIND("_",$A1,1)-1))),"")
in C column (city) put formula
=IF(ISNUMBER($B1),RIGHT($A1,LEN($A1)-FIND("_",$A1,1)),$A1)
I went through and used helper columns to determine if the data started with a number. If it did, I figured out if it also had a name in it. I then returned either the full data set or the data set truncated until the city name respectively. Column B:
=IF(ISNUMBER(INT(MID(A1,1,1))),MID(A1,1,IF(ISERROR(SEARCH("_",A1)),LEN(A1),SEARCH("_",A1)-1)),"")
Then I went through and determined if the data started with something other than a number. If it did, it was a city and I used the whole dataset for that record. If not, I tested to see if it had an underscore. If it did, there was a city present. I then used helper columns to determine where that underscore began and returned the city name. I left blanks in the helper columns to get only a single name or not. Then, I concatenated it all to get my final answer. The resulting super formula is this:
=CONCATENATE(IF(NOT(ISNUMBER(INT(MID(A1,1,1)))),A1,""),IF(IF(IF(NOT(ISNUMBER(INT(MID(A1,1,1)))),A1,"")="",IFERROR(SEARCH("_",A1),""),"")="","",MID(A1,IF(IF(NOT(ISNUMBER(INT(MID(A1,1,1)))),A1,"")="",IFERROR(SEARCH("_",A1),""),"")+1,LEN(A1))))
It is ugly, but it will get the job done. I would recommend copying and pasting directly into the worksheet instead of using VBA. But, if you must use VBA, loop through column B and C and apply the formulas provided into the cell formula property. I hope that helps.

Fetching data from row N+M, N+2M,... when N changes

My Google spreadsheet has webpage data imported with IMPORTDATA() on Sheet1. The data of interest are 20 pcs of 12-row deep posts starting at row N (e.g. row 123). Unfortunately, N changes each week or so.
Today I just use 20 hardcoded formulas that copy the data of interest to Sheet2 (e.g. =Sheet1!A123), but each time N changes I need to re-code all these 20 copying formulas on Sheet 2.
I'd prefer a method using e.g. Indexing or Offset formulas, where I would only need to change one "starting index" value when N changes in the webpage. Help would be much appreciated!
EDIT : Hi, thanks for your interest, sorry for delay. So this is the data structure of my Google spreadsheet. The source data can be considered a product list or similar.
Sheet1:
A1 =IMPORTDATA (url)
A2 to A122
A123 product 1 name
A124 product 1 price
A125 to A132... other product 1 data
A133 product 2 name
A134 product 2 price
A135 to A142... other product 2 data
A143 product 3 name....
... and so on up to product 20.
On Sheet2 I then want the following result:
A1 product 1 name
A2 product 1 price
A3 product 2 name
A4 product 2 price.
... and so on.
The problem is that the "uninteresting preamble data" in the beginning changes in length (number of rows) every now and then.

VBA Loop Statements Excel, Matching, Counting

I've never written an excel VBA statement before and would like some guidance.
I have a workbook with multiple sheets open. I'm trying to match data on sheet 5 with data on sheet one and count the sum of all values that match.
Sheet 5 looks like this:
Company Name Matches
Company A 57
Company B 31
Company C 20
Company D 10
Sheet 1 looks like this:
Company Name Dollar Amount
Company A 45000
Company B 50000
Company A 60000
Company A 62000
Company D 70000
Sheet 1 is several hundred lines long.
Basically, I need to count the aggregate dollar amount in Sheet 1 for all instances where the company name in sheet 1 matches the company name in sheet five.
I tried a countif and countifs statements in excel. I did not receive the result I needed. I think I need to use a do until loop to calculate what I need. Unfortunately, I have no experience in this area (my expertise is law).I'm sort of stuck knowing where I need to go but not sure how to get there.
I'd appreciate any help. Thank you for your time.
Assuming that your Aggregate Dollar Amount ("Total") is on column B in "Sheet 1" then on B2 you would place the formula:
=SUMIF(Sheet5!A:A,Sheet1!A2,Sheet5!B:B)
This will add all Dollar Amounts on "Sheet 5" if the corresponding values on Column A is equal to A2 (ie "Company A"). You can then drag down it will reference the appropriate company name. Regards,

How to copy to cells from a range if the columns to the right match?

I looked for a solution for this using VLOOKUP and programmatically and I couldn't find it. I hope you guys can help.
I have two spreadsheets with same headers and similar data. One is complete the other is not. The first column (lets call it "ID") of the completed spreadsheet messed up.
I want to copy the values from the "ID" column of the incomplete version to the new version based on if the cell to the right of each (lets call it "Names") matches.
To clarify, the algorithm or formula has to look through the column "Names" of the OLD (incomplete) version and if it finds a match in the NEW version, copy it to its left.
I cannot just sort alphabetically and copy and paste, because the completed worksheet has some duplicates that may be needed.
EDIT: EXAMPLE OF MY DATA:
Sheet1 Sheet 2
ID NAME ID Name Age
112 John 156 Dog 11
113 Bob 1xx Bob 15
156 Dog 1xx Bob 16
1xx John 18
Since the ID is messed up (because the ID I work with got messed up when exporting from Google Fusion Tables) I need to copy to the NEW file the "Ids" from the OLD version. This is just a simple example, I have over 200 000 rows of data.
Assuming ID is in A1 on both sheets and that the xx indicate IDs to be replaced, please add a new ColumnA in Sheet 2 and in A2 there:
=IF(ISNUMBER(B2),B2,INDEX(Sheet1!A:A,MATCH(C2,Sheet1!B:B,0)))
copied down to suit.
The first part ISNUMBER(B2) tests for a numeric ID in the data set that is a mixture of sound and corrupt. If that is a number and corrupt there may be no way to identify the corruption from the information provided.
So if that test is passed accept the value from the corrupted sheet (ie B2).
If however the test fails, then find the relevant Name's location (for Row2 the relevant name is Dog) in the incomplete sheet (ie Row4) and use INDEX to lookup the value associated with Dog (to its left) in the incomplete sheet.
Assuming the new spreadsheet is called "New" and the old is called "Old," and assuming that the names appear in column A of each spreadsheet, starting in row 1, then use this formula in column B of the new spreadsheet:
=iferror(vlookup(New!A1,Old!$A:$A,1,false),"?????")
So your spreadsheet looks like this:
A B
1 Coke =iferror(vlookup(New!A1,Old!$A:$A,1,false),"?????")
2 Pepsi =iferror(vlookup(New!A2,Old!$A:$A,1,false),"?????")
3 Sprite =iferror(vlookup(New!A3,Old!$A:$A,1,false),"?????")
4 asdfvasdl =iferror(vlookup(New!A4,Old!$A:$A,1,false),"?????")
5 Dr. Pepper =iferror(vlookup(New!A5,Old!$A:$A,1,false),"?????")
and it should display like this:
A B
1 Coke Coke
2 Pepsi Pepsi
3 Sprite Sprite
4 asdfvasdl ???????
5 Dr. Pepper Dr. Pepper

Excel Lookup Data Based on Column Name not Cell Name

I am trying to accomplish a strange task in excel and don't know how to go about it. I'm using Excel 2007 at work and I know very basic vba.
I want to automate a process where a person takes three spreadsheets and dumps certain data from them into one master sheet. The three spreadsheets vary every month in their column order, so unfortunately I can't just program vlookups to run and get the data.
I could be wrong, but it seems like Vlookup Match, Index Match Match, etc. wouldn't work either because they are still referencing cells. I basically need something that will find a column based on the text in the column, rather than its location, because the location will change, but the text will always be the same.
I have two ideas but I have no idea if they work and don't really know where to start on implementing them:
Convert the three spreadsheets to tables and reference the headings with table syntax (I haven't been able to get this to work)
Complex VBA that IDs everything
Can anyone help point me in the right direction to accomplish this task? Thanks so much for your help.
EDIT EXAMPLE
My main template that I'm trying to dump things into is just going to have the ID#s and empty columns:
ID# AltID# Deal
1
2
3
4
5
And then another spread sheet might have look like this
ID# AltID# Deal
1 10101 AAAA
2 20202 BBBB
3 30303 CCCC
4 40404 DDDD
5 50505 EEEE
I could of course vlookup, but the problem is next month, those columns in the second spreadsheet won't be in the same place, in the same order. They could be all the way on colum DD or whatever. So I need a formula that looks them up regardless of the columns location. Just matching them by the heading text. I hope that clarifies...
If you combine VLOOKUP with MATCH you can search based on column name, not index. Remember that the MATCH function returns the numeric index of the match. Let's assume that your data looks like the below:
NAME DAY1 DAY2 DAY3
Bob 123 345 567
Tim 456 789 998
A functioning Vlookup to return the DAY2 column for Tim would look like:
=VLOOKUP("Tim", A2:D3,MATCH("DAY2",A1:D1,0),FALSE)
A couple of notes. Where I've hard coded in words, you can use cell references.
Here is one idea:
get the index of the column ID# in Sheet2 MATCH("ID#",Sheet2!$1:$1,0)
convert to a character: CHAR(MATCH("ID#",Sheet2!$1:$1,0)+64)
get the column range:
INDIRECT(
CONCATENATE("Sheet2!",
CHAR(MATCH("ID#",Sheet2!$1:$1,0)+64),":",
CHAR(MATCH("ID#",Sheet2!$1:$1,0)+64)))
similarly for column AltID#:
INDIRECT(
CONCATENATE("Sheet2!",
CHAR(MATCH("AltID#",Sheet2!$1:$1,0)+64),":",
CHAR(MATCH("AltID#",Sheet2!$1:$1,0)+64)))
with range of ID# and AltID#, we can do the match+index:
=INDEX(
INDIRECT(
CONCATENATE("Sheet2!",
CHAR(MATCH("AltID#",Sheet2!$1:$1,0)+64),":",
CHAR(MATCH("AltID#",Sheet2!$1:$1,0)+64))),
MATCH(A2,INDIRECT(
CONCATENATE("Sheet2!",
CHAR(MATCH("ID#",Sheet2!$1:$1,0)+64),":",
CHAR(MATCH("ID#",Sheet2!$1:$1,0)+64))),0))
Here is an idea to consider:
Give a name to cell ID# e.g "dataJanuary" and use this named-cell as reference using an OFFSET function then you can explore it with vlookup or index-match function or other method.
Next month even if the ID# column is moved to other column or row, it will always reference to the same data since the cell is already named with "dataJanuary".