Macro to compare between two columns - excel

I need to compare two columns and find out what is missing in one of them.
Color available color required color missing
Blue, red (blue,white) or (blue,green)
White (green) or (red)
Blue,white,green (blue,white,pink) or (x,y,z)
I have a list of around 300 rows that I need to work on on a daily basis, which is very time consuming.
Can someone please help me get this information under column color missing?

This is not the type of question that will get answered here. Firstly, you are very unclear what you seek. Secondly, I suspect you will need a lot of code to achieve your objective.
Stack Overflow is for programmers seeking help to improve their code. It is not a free-coding site.
This is my guess of your requirement
Color available color required color missing
Blue, red (blue,white) or (blue,green) (white) or (green)
White (green) or (red) (green) or (red)
Blue,white,green (blue,white,pink) or (x,y,z) pink or (x and y and z)
As far as I know Stack Exchange, the parent site, does not have a site for help with designing programs which I believe is what you need.
You must first design your program. What tasks must be performed to achieve your objective? You then need to attempt to program each of those tasks in VBA. If you fail at a particular task, post your faulty code here with an explanation of its objective. If a task is small and you do not have a clue where to start, a question here might be answered.
First question for you: how much VBA do you know? There seems to be a belief that you can scan the internet for bits of VBA script and stitch then together into working program with minimal knowledge of VBA. I do not share this belief. I have tried searching the internet for answers to what I think are simple questions. I have found answers that I know include the required code but I cannot see how you could extract that code from the noise without VBA knowledge. You can search the internet for "Excel VBA Tutoral" or you can find a book in a good library or bookshop. Spend some time getting a basic understanding of VBA. That investment in time will repay itself quickly.
Below is my attempt at an initial list of tasks.
You imply the number of rows varies from day to day. You need to discover the last used row today. You need to know how to address a particular worksheet cell so you can access its value. You can access worksheet cells directly but it is faster and usually more convenient to copy the worksheet to an array. This is all basic worksheet access information.
In column 1, you have colours (some with capital letters) separated by comma or comma space. To process these colours you need then in an array:
Avail(0) = blue, Avail(1) = red
Avail(0) = white
Avail(0) = blue, Avail(1) = white, Avail(2) = green
The function Split will split strings like these into an array containing the values I have shown: Avail = Split(Col1Value, ",") Function Trim will remove leading and trailing spaces. Function LCase will convert upper case characters to lower case.
Column 2 is more complicated. In all your examples, you have a single " or " and the colour groups are surrounded by brackets. Can there be more than one " or "? Are the groups always surrounded by brackets? Could the spaces around the "or" be omitted so an example could be: (red, green)or(blue,white) or (red, green)or (blue,white)?
If the values in column 2 are inconsistent, I suspect the easiest solution is to make them consistent. For example:
Col2Value = Replace(Col2Value, ")or(", ") or (")
Col2Value = Replace(Col2Value, ") or(", ") or (")
Col2Value = Replace(Col2Value, ")or (", ") or (")
You could then use Split: Alternative = Split(Col2Value, " or ") to give:
Alternative(0) = (blue,white)
Alternative(1) = (blue,green)
For each alternative, you need to trim any spaces, remove the leading and closing brackets and split it like the Col1Value. You now have two arrays and you can search the second for values missing from the first and build a list of missing colours.
I hope this is enough for you to understand what I believe you must do. I have split the total program into small tasks. Gaining access to the worksheet. Splitting column 1 values into separate colours. Making column 2 values consistent if necessary. Splitting Column 2 values into alternatives. Splitting alternatives into required colours. Each of these is a straightforward task which you should be able to solve with relatively simple VBA.
Good luck.

Related

Excel percentage increase based on formula

I am trying to fill the sell price column in an Excel spreadsheet with the increased values in colors based on the round up columns value (1 to 50 green, 50 to 100 blue, 100 to 150 yellow, 150+ pink).
I've opted for the percentage table because some items can be sold for a lot more than what I have purchased them for, so that's just for my benefit. I am open to any other suggestions and I am new to this whole business thing.
I was using IF in my formula which would work great for using one percentage increase in the formula:
=IF($E27<50,ROUNDUP(I$27,-1))
If I try to enter a second argument like
=IF(OR($E28<50,ROUNDUP(I$28,-1)OR($E28>50,<100,ROUNDUP(J$28,-1))))
I will get an error.
I'm probably using the formulas wrong, I've tried "AND" and a couple other formulas, but I can't find anyone else trying to achieve the same or similar.
So something like this:
=IF($E28<50,ROUNDUP(I$28,-1),IF($E28>50,ROUNDUP(J$28,-1),"Error"))
But not sure what the <100 was for.
Although the problem is not completely clear, I understand that you want to add a formula with nested if statements.
I will recommend you to try nested ifs in parts.
=IF($E27<50,ROUNDUP(I$27,-1),"First if condition is false")
If everything is working as per the requirement then edit that text in the formula to add another if statement.
=IF($E27<50,ROUNDUP(I$27,-1),IF(OR(condition 1, condition 2,more conditions),"value if true","value if false"))
In the second argument provided by you, the arguments of the OR function has not been properly provided. Ensure that all the arguments of an OR function are conditions separated by a comma.
$E28<50 This is a condition so it's ok.
But other arguments are not making sense.
Also, using OR multiple times inside the first OR arguments is not clear.
It would be beneficial if you could provide the basic table and mention the requirement clearly.

extract certain text after certain characters

what is the easiest way with an Excel formula to extract certain details from a cell? So for example, if this is in cell A1 column=""HMI_LOCATE"" px=""CLASS"" position=""99"" validation=""ROOM"" then I'm trying to extract just the data the falls in between the double "" after the px= so in this example, I need to extract just the letters CLASS and nothing else, what is the easiest way to extract that data, the part I'm trying to extract won't always be 5 characters long it could be much longer or shorter.
Do you want to achieve this?
With o365 you can use this formula
=FILTERXML("<t><s>"&SUBSTITUTE(A1,CHAR(34)&CHAR(34),"</s><s>")&"</s></t>","//s[position() mod 2 = 0]")
or for older EXCEL-versions
=IFERROR(INDEX(FILTERXML("<t><s>"&SUBSTITUTE($A$1,CHAR(34)&CHAR(34),"</s><s>")&"</s></t>","//s"),ROW(A1)*2),"-")
This splits the string at the quotation marks (CHAR(34)) and builds an array of elements. Then every second element is put out.
For tons of other possibilities have a look at this awesome guide by JvdV.
EDIT:
To get the element after px= no matter where it is, you can use
=LET(list,
FILTERXML("<t><s>"&SUBSTITUTE($A$1,CHAR(34)&CHAR(34),"</s><s>")&"</s></t>","//s"),
INDEX(list,MATCH("px=",list,0)+1)
)
The LET-function lets you assign functions to variables which then can be used for further calculations.

Replacing numeric values in Excel sheet with text values from other sheet

I am using Surveymonkey for a questionnaire. Most of my data has a regular scale from 0-6, and additionally an "Other" option that people can use in case they choose to not answer the item. However, when I download the data, Surveymonkey automatically assigns a value of 0 to that not-answer category, and it appears this cant be changed.
This leads to me not knowing when a zero in my numeric dataset actually means zero or just participants choosing to not answer the question. I can only figure that out by looking at another file that includes the labels of participants answers (all answers are provided by the corresponding labels, so this datafile misses all non-labeled answers...).
This leads me to my problem: I have two excel files of same size. I would need to find a way to find certain values in one dataset (text value, scattered randomly over dataset), and replace the corresponding numeric values in the other dataset (at the same position in the dataset) with those values.
I thought it would just be possible to find all values and copy paste in the same pattern, but I cannot seem to find a way to do that. I feel like I am missing an obvious solution, but after searching for quite a while I really could not find an answer to my specific question.
I have never worked with macros or more advanced excel programming before, but have a bit of knowledge about programming in itself. I hope I explained this well, I would be very thankful for any suggestions or scripts that could help me out here!
Thank you!
Alex
I don't know how your Excel file is organised, but if it's like the legacy Condensed format, all you should need to do is to select the column corresponding to a given question (if that's what you have), and search and replace all 0 (match entire cell) with the text you want.

Separating data set by how many spaces are before first letter

I have a huge data set that I need to separate into a hierarchy. Currently the only way to tell which level the data point is in the hierarchy is how many spaces are before the first letter (It is from an Essbase pull). I need to separate it out into various columns so that I can see the structure more effectively. There are 7 different numbers of spaces (the separation between hierarchy levels). I honestly have no idea how to get this done. Does anyone have any thoughts or advice?
You can use this formula:
=IF(COLUMN(A:A)=FIND(LEFT(TRIM($A1),1),$A1),TRIM($A1),"")
Drag across and down.
If you do not want 15 - 40 spaces and it appears that all are multiples of 5 you can do this:
=IF(COLUMN(A:A)=INT(FIND(LEFT(TRIM($A1),1),$A1)/5),TRIM($A1),"")
Using the examples in column B:
Insert column A before data. Then, get length (len) before triming (trim) spaces and after (trim) and subtract. (This assumes no spaces at end however)
=LEN(B1)-LEN(TRIM(B1))

How to assign conditional values based on row and formatting

I am thinking this is gonna be a simpler answer than I'm making it, but here goes nothing. I have a project I am working on using Excel and Python, where I am going to calculate the results for a season of NASCAR using the different points systems. I had tried doing this only using Python, but figured doing it in Excel first is better. The thing is, I have all the results for all 36 races inputted in Excel, with formatting for drivers who lead a lap, drivers who lead the most laps, and drivers not elligible for points.
How I have the formatting is as follows:
Inelligible driver's names are in red text.
Driver(s) who lead a lap are in bold text.
Driver(s) who lead the most laps are in bold text and bold border.
Driver(s) who had penalties have a red background.
Is there a way I could assign values based on these formatting conditions?
As for the penalties, those I could calculate separately if needed.
Please let me know whatever you may suggest.
Each column contains the results for a single race, and since there are always 43 drivers, the block of cells contains 43 rows (plus a heading row with each race name).
An option I'm thinking of is, to have the results for each race on Sheet1, then on Sheet2 have a list of all valid driver names, then copy and paste it twice, one for each option (2 bonus points, 1 bonus point, and no bonus points), and name each list. Also, I will have names for each driver, as well as names for each position. Then, when calculating the points after a race, use an if-then-else formula similar to the following:
IF A2 = driver_most_led [Driver_Name = Driver_Name + Position_Points + Most_Led_Bonus], ELSE IF A2 = driver_lead [Driver_Name = Driver_Name + Position_Points + Lead_Bonus], ELSE [Driver_Name = Driver_Name + Position_Points])
I know it's a long example, but not sure if this is legit or not.

Resources