Split Excel sheet into multiple sheets - excel-2010

I would like to break an Excel Sheet into multiple sheets
For Example:
Lets say there is a sheet with 7 columns as shown below
Column1, Column2, Column3, Column4, Column5, Column6, Column7
I would like to break it into 3 sheets like shown below, Column1 would be common in all sheets.
Column1, Column2, Column3 -- Sheet 1
Column1, Column4, Column5 -- Sheet 2
Column1, Column6, Column7 -- Sheet 3
Is this possible? I had been searching the internet for a solution for almost a day now, but I have not got any related solution.

This will DO what you WANT:
Sub DataToDiffSheets()
Dim count As Long
count = Application.CountA(Range("A:A"))
Range("A1:A" & CStr(count)).Copy
Sheets("Sheet2").Select
Range("A1").Select
ActiveSheet.Paste
Sheets("Sheet3").Select
Range("A1").Select
ActiveSheet.Paste
Sheets("Sheet1").Select
Range("D1:E" & CStr(count)).Cut
Sheets("Sheet2").Select
Range("B1:C" & CStr(count)).Select
ActiveSheet.Paste
Sheets("Sheet1").Select
Range("F1:G" & CStr(count)).Cut
Sheets("Sheet3").Select
Range("B1:C" & CStr(count)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheets("Sheet1").Select
End Sub
It's not the best and it's not the cleanest, but it'll work.

Related

Join 2 Sheets together on particular columns

I have a Google Sheets Document with 2 Sheets, Inventory and Pending Transactions.
My goal is to create a new sheet with Available items.
Company,Item,Quantity
Walmart,ToyA,100
Walmart,ToyB,5
Amazon,ToyA,2000
Amazon,ToyB,100
Amazon,ToyC,5
----
Company,Item,Pending
Walmart,ToyA,2
Walmart,ToyB,4
Amazon,ToyA,1990
My idea is to Join the Items together.
Company,Item,Inventory,Pending,Available
Walmart,ToyA,100,2,{Computed}
Walmart,ToyB,5,2,{Computed}
Amazon,ToyA,2000,1990,{Computed} # All of the {Computed is Inventory minus Pending}
Amazon,ToyB,100,2,{Computed}
Amazon,ToyC,5,2,{Computed}
My Original idea was to Show the items merged on a Primary key of Company:Item, but i have no problem creating a new sheet which handles all of this. I was trying to do things like: =Query({Sheet1!A:D;Sheet2!A:D}, "select *") but that appends Sheet2 to the End of Sheet1, which is not what I wanted.
I got stumped, and after looking at a bunch of different Questions I couldnt find the example I was looking at.
To merge the items without blank rows, use
={QUERY(Sheet1!A2:D, "SELECT * where not A like '' ");
QUERY(Sheet2!A2:D, "SELECT * where not A like '' ")}
if you want to know from which sheet the data are coming, use
=QUERY({
ARRAYFORMULA({IF(ISBLANK(Sheet1!A2:A),,"#1") ,Sheet1!A2:D});
ARRAYFORMULA({IF(ISBLANK(Sheet2!A2:A),,"#2") ,Sheet2!A2:D})
},"select * where Col1 <> '' ")

Google Sheets Query using important range and a dynamic cell reference

I have a roster of students (Sheet 1) and I need a formula to search another sheet (Sheet 2) to see if each student on Sheet 1 is also on Sheet 2 and if they return the word "yes"/ if they are not I would like the cell to remain blank.
This is the formula I have:
=QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/1395p5J5oN4vYLPeyAdUQDZluwxWU53NYJPiqeHdXSEw/", "Quarter 3!A3:H"), "Select 'yes' where Col1="&$A7&"")
The formula is not working properly.
For students that are on Sheet 2 the formula is returning two rows of data (two rows of "yes) and the first instance of "yes" include characters that I did not include in the query:
For students not on Sheet 2, the formula is returning a yes with the extra characters "yes"().
I feel like I should be using an IF function, but I could not get it to work with IMPORTRANGE
use:
=QUERY(IMPORTRANGE(
"1395p5J5oN4vYLPeyAdUQDZluwxWU53NYJPiqeHdXSEw", "Quarter 3!A3:H"),
"select 'yes' where Col1="&$A7&"
label 'yes''')

How to reduce Inventory in sheet1("stock") on the bases of product sold in sheet2("sales") through google sheets script...?

In Google Sheets for inventory management, sheet1 is stock in which Product and Quantity are mentioned, sheet2 is the sale of the day. I want to automatically deduct stock when a product is written over there, if apple is sold, then it should automatically deduct one quantity from sheet1.
The sheet is here.
Some code like this:
function onedit(sheet2,A2) {
if the product in Sheet2!A2 is in Sheet1!A2:A,Subtract 1 from Sheet1!B2:B
}
In your cell B2, you can insert this formula:
= 4 - SUM(QUERY(sold!$A$1:B,
"select count(A)
where A = '" & A2 & "'
group by A", false))
Then, you can drag it down to let the formula apply to all your rows.
The formula counts the number of occurrences in the "sold" sheet of the term in the column A of the first sheet. The QUERY function returns a table with one column and two rows (header and data). the SUM is applied to it, and reduces the QUERY result to a single number.
As with all formulas, results are kept up to date by the Google sheet automatically.
Instead of having the initial inventory in the formula itself, I suggest to use a separate column, for example column C. The formula above would then start with C2 instead of 4.

Select Random item from list in Google Sheet

Im working on a google sheet document to randomly pick a protein and a side dish for weeknight meals based on a selection. The idea is you select your meat (chicken, beef, pork, etc) and the max amount of calories for the meal and it will select a protein and side dish randomly from a list. Not sure how to go about writing either the equation or a script to do this though. Heres what im working with so far:
This is the main page where you select what you want
This is the protein sheet that will have all the possible selections, so based on the image above would want to randomly pick a chicken dish with 800 or less calories
And finally this is the side, for this I would want to choose a side that is less than the remaining calories, so if the protein had say 500 calories would want a side with 300 or less:
On the Proteins sheet add E3 =randbetween(1,100) and copy the formula down. On the Side/Vegetables add C3 =randbetween(1,100) and copy down. On the Dinner Generator sheet add this query to A8:
=query(Sheet2!A3:E,"select A,B where D contains '"& A3 &"' and B <= "& B3 &" order by E desc Limit 1")
and this to A9:
=query(Sheet3!A3:C,"Select A,B where B <= ("& B3 &" - "& B8 &") order by C desc Limit 1")
And this to A10:
=B8+B9
I named the sheets Sheet1, Sheet2, and Sheet3. Change the sheet names in the queries as needed. I also used desc in the queries so blanks would be at the bottom allowing the lists to be expanded without having to change the queries. I suggest you change fish entries in column D to Fish instead of Tuna, Salmon, etc. Below is a shared example spreadsheet. Make a copy to test.
https://docs.google.com/spreadsheets/d/17SWtKfzDFDV8OeffR7s5PcmmwRMzu6UKzWK26CX7KDU/edit?usp=sharing

Data reduction via IMPORTRANGE

I am trying to do some data reduction in my Google Sheets by using the following IMPORTRANGE formula:
=query(importrange("https://docs.google.com/a/ap.averydennison.com/spreadsheets/d/1xz1lXY-w5Ii_aWqVAhHgRCmeoes9ltSUtibE4kzhMHA/edit#gid=2051232966","SF_Flex_Rel!a:l"),
"select * where Col1 = '"&text(B1,"###")&"'",1)
The 'source' sheet has a whole lot of sales data records. What I am trying to do in the new sheet via this formula is only bring in the sales records from the source sheet that match the customer number specified in cell B1.
It seems to work OK if I limit the IMPORTRANGE to only query about 10,000 rows. Once I go over around 20,000 rows the screen will briefly flash up the records, then a small progress bar shows in the top right corner of the sheet and the records disappear. The cell with the formula just shows #ERROR! with no other comments to tell me why.
Is there something wrong with my formula syntax?
Is there a better way to achieve this data reduction?
Is there some undocumented data limitation on IMPORTRANGE function (I am using 'new' Google Sheets)?
try like my example :
=QUERY( // data
IMPORTRANGE(
"Spreadsheet Key", // spreadsheet key
"DATA!A:C" // datarange
),
"SELECT Col1 WHERE Col2=" & "'" & B2 & "'" // query
)
I had the same problem. This answer helped me find a workaround : https://productforums.google.com/forum/#!topic/docs/RxVUFGWQ2Y4
In my example :
1) In the spreadsheet where the data is I have added a few empty columns (E to H) in order to display 4 columns of data in 5 maximum rows.
=Query(Sheet1!A:D,"select * Where A contains 'KEYWORD' limit 5",1)
2) Then in the other spreadsheet:
=ImportRange("https://docs.google.com/spreadsheets/d/ss_key_here/", "'Sheet1'!E1:H5")

Resources