How to reference a value to a range of numbers in another list then have values returned from 2 different places where the value is found [closed] - vba

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I hope my title made some sense. In essence I am trying to do this with very little programming experience and I understand now that I very much need help. I have been attempting to use Visual Basic because I am trying to sort through a very large list of unrecognized genes. Overall, I am trying to check whether ANY of my "midpoint" (original gene location) values lies in-between any row's "startpoint" and "endpoint" (known gene locations). If it does, then I need both code and name returned to me somehow, even if it matches in more than one row. To make matters worse, it should only do this if its "midchrom" matches the respective row's "chrom".
The list happens to be 3k rows long, hence why I would like to do it this way. I hope I explained myself well enough.. An example of the list is copied at the bottom (I hope csv is fine, first time asking here). I have been able to write no code at all since I don't know how to approach the problem at all, and I've been at it for 2 days, so I have sadly nothing to post.
Any suggestions appreciated! Thank you!
midchrom,midpoint, code, chrom, name, Startpoint, endpoint
chr1, 10052729.5, NM_018896,chr1, Name1, 117328105, 117475235
chr1,10249243,NM_001177888,chr1,Name2,109035529,109052409
chr1,1103696.50,NM_001256327,chr1,Name3,125766078,125845734
chr1,1112610.00,NM_001256360,chr1,Name4,125766078,125845734
chr1,11947610.5,NM_198383,chr1,Name5,12470846.00,12460843.00
chr1,12249877.50,NM_198396,chr1,Name6,125766225,125845740
chr1,12383427.00,NM_001256325,chr1,Name7,109035526,109052415
chr1,12410787.50,NM_020084,chr1,Name8,12383158,12451963
chr1,12470843.00,NM_001003406,chr1,Name9,12383158,12451963
chr1,12494320.50,NM_009783,chr1,Name10,109035538,109052412
chr2,12529476.00,NM_171733,chr1,Name11,125766225,125845740
chr1,12809629.00,NM_001256334,chr1,Name12,125766078,125845734
chr1,12909892.00,NM_001256329,chr1,Name13,175711654,176178148
chr1,13200078,NM_001029326,chr1,Name14,175711654,176281155
chr13,13706259.5,NM_001256328,chr2,Name15,192931857,192942982
chr1,1451461.5,NM_001193140,chr2,Name16,192931857,192942982
chr1,14004645.5,NM_001256359,chr1,Name17,176007934,176281155
chr1,15906995,NM_031601,chr1,Name18,142223122,142606517
chr1,15956960.5,NM_001044308,chr13,Name19,13709000,13706230

As pnuts suggested, you can do this without VBA by creating a matrix:
Add two rows above your data
Tranpose columns "midchrom", "midpoint" and "name" to top-right of your data as in the screenshot. use Paste Special->Values & Transpose
Place the following formula in the top left of the new "table/matrix": =IF(AND(H$1=$D4,H$2>=$F4,H$2<=$G4),H$3,"") - and copy it down and across. If it's 3k gene, the calculation might take a bit, but shouldn't be too long
Every row now shows the names of all genes whose' midpoints lay in between the start- and endpoint of the row's gene (assuming it the same chromatin)
Here's the sample file.

Related

F4 search help based on a structure. How does it work? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I've recently been taking closer look at the Function Module 'F4IF_FIELD_VALUE_REQUEST' and saw that you can pass a table, but also a structure to the Parameter 'TABNAME'. When you pass a table name, the F4 help will obviously present entries of said DB-table, giving you the possibility to choose one of them as a value for your parameter. But how does it work if you pass the name of a structure? Since the structure is only a Datatype it doesn't contain any Data itself. Where is the Data I see in the F4-Help coming from then?
thanks in advance,
Jellyfish
When you pass a table name, the F4 help will obviously present entries of said DB-table
No, not necessarily.
It will use the search help defined for that field in the dictionary definition of the database table / structure. You can see those in the transaction SE11 on the tab "Input Help/Check".
The search help for each field might be:
Implemented with a check table, which is usually not the table you are looking at. See the column "check table" to see where the values come from.
Implemented with fixed values. The possible values are taken from the domain of the data type.
Implemented by a specialized picker for that data type (dates and times)
Implemented by an explicit search help, which might:
use a table or view
use a search help exit, which is a function module which provides the data procedurally
or both: The function module receives data from the database and can then process it before it is shown to the user

VBA Excel Convert 3 Columns into an Arrary [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have been searching for a way to do this and I feel like I'm hitting a wall. . . I'm new at VBA, so I may not be going about this the right way.
I have a table that looks like this:
I need it to look like this:
The client needs to use this data for various purposes. They tried a Pivot Table, but they hated how it looked and their end users didn't like it either. They also do a lot of other tweaks to the data after it's in the final format.
I was able to get the Names and the Questions to copy/paste to a new sheet in the correct layout. I was then trying to do a For Each loop to filter the Name and copy/paste/transpose the answers to this new sheet. I went this method because the number of questions and names vary all the time.
I do not understand the code I've been seeing and I'm unsure how the older examples I've found online can be manipulated to match my case.
Any suggestions? Or is there another post that is doing something pretty close to what I'm trying to do that I've missed?
Thank you!!
You can do this simply with Power Pivot (a free MS add-in in 2010-2013 (aka Data --> Get & Transform in 2016)
Merely
select the Questions Column to Pivot (create new columns)
Values column --> Answers
Advanced Options Do not aggregate
This is the result using your data as posted:
The only formatting change I made was to turn off the Filter Button under Table Options.
Asuming that the names are sorted and every name does have the same questions, you could run a simple "double match -1" to get the answer as a worksheet formula. (Having list 1 in sheet1 and list 2 in sheet2)
=INDEX(sheet1!$C:$C,MATCH(B$1,INDEX(sheet1!$B:$B,MATCH($A2,sheet1!$A:$A,0)):sheet1!$B$99999,0)+MATCH($A2,sheet1!$A:$A,0)-1)
Formula for B2. Fill right and down.
If you don't want the formulas, hide the sheet and copy/paste values only via VBA to another sheet.
Names do not need to be in complete order but being together "aabb" and "bbaa" will work but "abab" or "baab" will not. Questions do not need to be in any order, but having no "q1" for someone will give him the next "q1" which is found by another name.

Excel VBA: merge (SUM) rows based on column value [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a randomly generated list of languages with different wordcount per file and I need to merge (SUM) function lines based on value in Column A.
Basically I need it to merge lines(values) for columns B - J based on the value on Column A. Only if the values are the same otherwise do not merge anything.
More lines for one language means there is more files for that language. If there is more files then I need to get total wordcount by merging the lines.
Please see reference images below:
Source table
Updated table
Any ideas?
EDIT1: I have a large macro that loads CSV with all these data and process them. My goal is to have one button macro that will import a CSV and process the data in the formatt I need. There is several dozens of code to make it look like on the screenshot above. Last thing is to merge the cells. Any advice is appreciated.
Select the leftmost cell BELOW you data and hit the button at the "data" tab.
With the new window: mark your range, select "Sum" and at "Use labels in" hit "left column" and "OK"
This will give you your summed list:
Just a hint: With record macro () you get the code for this like:
Selection.Consolidate Sources:="[Book1]Sheet2!R2C1:R11C10", Function:=xlSum, TopRow:=False, LeftColumn:=True, CreateLinks:=False
And the best part: You can do this with external data! So directly importing from your csv is possible ;)
To do the "real code" is up to you. ;)

How to get data from one worksheet to another programmatically? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am trying to populate or get the data from following table in excel to another table. I want to write code in excel VB to do the following :
Search the first col JOB -->find the job name
Search the third col HOUR -->find the hour
According to the job name and hour get the value Col GCP_SECS for correct job and hour
put the value into anoher table .
I have no experience on Execel VB , really need someone to help me with this .
Thanks for your help!
JOB DATE HOUR GCP_SECS
GEMAB1PV 8/17/2015 12 1021.42
GEMAB1PV 8/17/2015 13 862.24
GEMAB1PV 8/17/2015 14 269.18
GEMAB7PV 8/17/2015 14 671.87
GEMAB7PV 8/17/2015 15 1034.24
This sounds like a perfect candidate for Index/Match (the "extended" type too, using two lookups and entering as Array - good stuff!)
NOTE: Enter that formula with CTRL+SHIFT+ENTER.
So, if you have two cells that have a Job Name and another with Hour (in my screenshot, this is G3 and H3. Use those as your Match() requirements, and then use where they appear in your table as the Match() ranges (note the use of & to connect the two). And, since you want to return the GCP_SECS info, use D2:D6 as the Index() range.
Does this make sense? You can enter the Index/Match formula on any page.
Please use the below vlookup function with CTRL+SHIFT+ENTER for this:
=LEFT(VLOOKUP(J4&K4,C3:H7&F3:F7,6,0),LEN(VLOOKUP(J4&K4,C3:H7&F3:F7,6,0))-2)
see the below pic for more clarification:
Good Luck :)

Searching an excel with two search words (multiple lookup) using vba macro [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am using vba macros.
Task:
1) User will give two inputs viz. number of devices sold (column B) and week number (column A).
2) Search the excel file using these two and get the earnings.
(Conditions: 1. We dont have to modify anything in the excel file.2.And we have to first search devices sold and then we can go to week number.)
Note: Actually i have a different problem, this is generalization for that.
I used find function but I dont understand why its working.
Please tell what is to be done.
Consider the input is 11 and week 3 (so search for 11 and then check if its corresponds to week 3 or not. If not, move to next. I tried this but ended up in an infinite loop.)
You are looking for a Lookup with multiple criteria. A quick search gives several useful links, listed below. I have marked with * those that I have answered.
I have filtered out some of the links that actually deal with other issues.
As seen in the links, there are several options to achieve your goal. I personally prefer those that do not need array formulas, using an answer to question 1 with LOOKUP or an answer to question 2 with SUMPRODUCT.
Since you mentioned that you need a VBA solution, you can use WorksheetFunction to use an Excel formula in VBA code, or check answers to question 7.
Multiple Column vs Multiple Column Lookup *
Multiple-column based lookups in Excel *
Lookup Database (Multiple criteria)
Excel Lookup with multiple queries
Multiple VLOOKUP LOOKUP IF Statement?
Returning a value if three columns match in excel *
VLookup multiple columns
Comparing two columns in one Excel sheet, to two columns in another sheet, and if they match, copy data from another column *
Macro for vlookup with 2 vertical criteria *
http://spreadsheets.about.com/b/2014/01/08/excel-lookup-formula-using-multiple-criteria.htm
http://fiveminutelessons.com/learn-microsoft-excel/use-index-lookup-multiple-values-list
http://blogs.office.com/2012/04/26/using-multiple-criteria-in-excel-lookup-formulas/
http://www.xl-central.com/lookup-multiple-criteria.html
http://www.get-digital-help.com/2012/05/22/lookup-multiple-values-in-different-columns-and-return-a-single-value/
PS: The (probably partial) list of (probably) duplicated questions provided above shows the usefulness of what was proposed in https://meta.stackexchange.com/questions/211366/group-duplicate-questions-for-convenience
Concatenate week and number of devices and then search like usual one keyword search.
You dont need any VBA for such a simple thing. Use this array formula:
=INDEX(C2:C5;MATCH(1;(B2:B5=11)*(A2:A5="week 3");0))
Dont forget to enter the formula with Ctrl Shift Enter (it is an array formula)