Comparing two columns and matching values from seperate work sheets - vba

The goal of my project is to create an out of office program that will allow easy tracking and auditing of our Sharepoint site as it doesnt have a built in system to do. I have no background in VBA, but I have done quite a bit of python. That being said I've ran into my first issue. I'm not sure how the syntax works, and what commands I should be using to get the results I want. I.e. sheets vs worksheet vs worksheets.
I have a workbook, 1 sheet is Raw Data, in which I import data from a sharpoint site. It displays the following columns
Resource Name -- Absence Type -- ID -- Start Time -- End Time -- Created -- Modified by
The next sheet I have is tracking, it's called Tracking. On this page the user imputs Resource Names they want to track into Column A, and then the remainign columns are going to display the number of absences that name has so it will look something like
Resource Name -- Vacation -- Sick -- WFH
Clooney, George -- 2 -- 0 -- 7
A counter will run based on each instance that appears in raw data and adds the number to the counter based on the absence type from raw data.
I need a way to loop through Raw Data and look for the names that appear in the Tracking data. If Possible I'd like to store them in a third worksheet jsut for testing purposes. I know the logic I need to use, but what I dont know is the syntax to refrence the pages together. Any insight on the best way to accomplish this?
Question : I need to Search raw data for every instance Resource Name appears in it from the Tracking page and store into another worksheet.

If you don't want to use PivotTables (can be hard to search later) this is the way to do it with COUNTIFS. This formula goes in the "Sick" column of Tracking in row 2 (assuming row 1 is headers).
=COUNTIFS('Raw Data'!A:A,Tracking!A2,'Raw Data'!B:B,"Sick")
It assumes that in Raw Data Name is in column A and AbsenceType is in Column B, but it doesn't matter how many records there are.

The way I understand your question (and it wasn't easy), you are dealing with a bunch of timesheet info. You seem to be trying to count the number of instances of different kinds of time off that people are taking - whether that be vacation, sick or working from home(WFH).
I've never heard someone's name referred to as a "Resource Name" lol.
You really don't need to use VBA for this problem - at least not anything that you can't just record a macro for - it seems to be a rather simple problem that can you solve using a pivot table.
If you want to you can set up a vlookup reference to this pivot table to create the little form that you seem to be trying to create. But really I think your better off just teaching whoever is going to be using this about pivot tables. Let me know if I misunderstood your question and I'll be happy to delete this post.

Related

Dictionary vs pivot Table and some office issues

In company when I currently work we have big issue with MS excel stability, hence my question below.
Recently I just learned about excel Dictonary code.
I know pivot tables and how they work.
sadly the issue is not with pivot themselves but with excel. (IT dept. is working on the issue for 3 weeks now, and we dont know when / if they gonna fix it)
Hence my big ask for thi community:
I would need a userform working with the dictonary.
What I would need is to create a code that could work as pivot table but using dictonaries (since theoreticaly they are faster and are outside of VBA / excel basic in-build option)
so?
Can some1 help in creating such code?
Is this the right option?
I would like to see a userform where I can choose my Table(ctrl+T) headers to choose by which header i want to sum values up, and ofc I would have to be able to choose a column by which the dictonary summing is working on.
Thank you both for answering.
Lets start then.
I watched ExcelMacroMastery videos regarding dictionaries,
In this example, he used them to make a basic sum exactly like the basic functionality of Pivot table.
So since that's the basic use where I work I wish to have a dictionary macro from which I can choose the column by which I get unique values and 2nd column with a sum from the second provided column from a table.
the issue is: if I show any file or any example this could result in macro working for this specific case, and I would like it to be able to choose by Table's (CTRL+T) headers for the unique values and to use some way(like a dropdown menu) to choose the column by which the sum can happen.
This instability is due to 32 bit office suite 365 working n 64 bi PCs/ laptops and recent company update made it even worse, now there is an issue with even basic save file option.
Not to mention excel crashing for no apparent reason.
So to sum up,
I need dictionaries to kinda step up and replace basic summarizing functionality of an pivot table.
or to replace this non pivot way:
use unique function to determine unique values from specified column (non-table object sadly)
Use sumif or sumoifs function to summarize the specified amount/value for that unique list.
//EDIT:
I kinda found what I was looking for thus the edit.
Im showing the link to the file I wish to change a bit:
https://app.monstercampaigns.com/c/s0iavndiopijkrar8ghp/
to this file I wish to add a user form by which the headers of the report will be chosen from source data, and by which the sum will occur.

Excel VBA to select new data and transfer to the next blank line in another worksheet

I have found a couple places that this has been touched on but I am not a programmer by any means so I am having difficulty using what I have found. I have been teaching myself VBA for access but I am very lost as to how to go about this in excel.
I have two work sheets in my workbook. One is called "Field" the other is called "DTE" in the Field sheet I have employees tracking the number of ballasts that are installed at a certain job site. The DTE is more indepth and is the sheet that our customer needs. Our guys are not at all tech savvy so I need to find the easiest way (one button click type of situation) to have the information transferred from "Field" to "DTE".
Here is some information on the data:
Field contains three tables (they are currently left to right but I can make them top to bottom if that is messing the codes up)
The first table is for ballasts, second for fixtures. There third is not necessary for this question.
There are multiple types of ballasts and fixtures which is where the difficulty comes in.
For example:
I need to have certain information transferred over, on the field form the guys type the location as well as how many of each type of ballast/fixture. In the DTE I need this information to be arranged slightly differently.
If the Row in the field form looks like this:
Location Ballasts 1 Ballasts 2 The second looks like this:
Hall 3 4
and then I need the DTE to look like this
Location Quantity Type
Hall 3 Ballasts 1
Hall 4 Ballasts 2
I know this is extremely in depth and I apologize in advanced because this is much more difficult than I wanted to make it but if anyone could help I would really appreciate it. Thank you so much!
(Also if you think another answer may help please link me to it, I have tried to use many of them and alter them to fix my tables but I just come up with a ton of errors. Thank you again!)

extract data in exel sheet using macro

you most probably going to think "what an idiot" but remember i never done any type of coding before so this is all new to me,
My problem are that i'm working on a HUGE excel sheet with loads of data that is not needed. i need to sort the data into a few columns, i only need column "A,K,AN,AQ" but in column "AS" i only need certain values (yes,no,blank) i only want the yes and blank values. like i said never done any coding before but i know that you can use an macro to do it so please help, how do i go about this?
before trying to get into macros, try to use functions with if else statements. They are quite easy to handle. Like: If (yes) then put it into X. Later, you could select all needed. Also, check the, how the dollar sign is used
use this links to see, if it is something for you.
One quick and dirty way of getting this job done would be to:
Delete the columns you don't need.
Select all cells in the range you're interested in, click the Insert menu, and choose "Table". If your columns have titles, select the box for "My Table has Headers."
-This turns your data into an array so that Excel recognizes that each row is an entry (instead of thinking that the cells are unrelated).
Now you can use the filter icon in the column headers to select and display only the rows containing the values in column X that you're interested in.
Note that there are some limitations to what the table feature is good for, so, as always, whether this is a good solution for you depends on what you want to do with the data.

Query several ranges and add automatically a column to know the source of each row

I am trying to achieve the following in Google Spreadsheets.
First, I want to query several ranges (in different sheets from the same spreadsheet). I tried a formula like this =query(arrayformula({indirect(E2:E10)}),"select * where Col1 <>''") with no success
In E2:E10 I have a list of ranges. Column F contains a name that describes the source of the value in Column E.
My second problem is that I need to add a column to the output of that query that tells me the origin of each row.
If the sources are ranges of 3 columns by country I need to merge those tables and add that country to each row.
All credits to +Ben Liebrand who helped me out here: https://support.google.com/docs/profile/3464
"I just want to start of by saying that the indirect() function does not work in an arrayformula() function as expected. So you will need to take another approach. I can understand what you are trying to do so I added another TAB in your spreadsheet to demonstrate another approach. I know it was initially a specific design you were trying so I made some changes to what you had. Maybe you can take a look at what I have offered and maybe you can tweak your design.
I know what I am offering is just very rough but you will also notice that I removed the end row specifier from your ranges in the range table.
Don't assume my example to be the final result but I was just trying to show that the range you were trying to use with the indirect() function will not work.
So hopefully this will give you a new idea of how you can maybe handle this.
My formula also adds the country to each of the tables in the output. My formula looks like this
=query(ArrayFormula({
if(len(indirect(regexextract(F2,"\w+\!\w+")&":A")),G2,),indirect(F2);
if(len(indirect(regexextract(F3,"\w+\!\w+")&":A")),G3,),indirect(F3);
if(len(indirect(regexextract(F4,"\w+\!\w+")&":A")),G4,),indirect(F4);
if(len(indirect(regexextract(F5,"\w+\!\w+")&":A")),G5,),indirect(F5);
if(len(indirect(regexextract(F6,"\w+\!\w+")&":A")),G6,),indirect(F6);
if(len(indirect(regexextract(F7,"\w+\!\w+")&":A")),G7,),indirect(F7)
})," select * where Col1 <> '' ")
Hope this is of some help to you"
And I hope is useful to the community
GerĂ³nimo

Determining whether VBA is necessary in Excel, or if a pivot chart/table can suffice

I wish that I had a more precisely descriptive title for this question, but I am not very knowledgeable with Excel spreadsheets or VBA (I'm primarily a Java developer, and don't play much in the Microsoft world).
I'm trying to use an Excel spreadsheet to accomplish something. I need to determine whether I can get there with a PivotTable, PivotChart, or some other built-in functionality... or whether I need to go down the path of writing custom VBA code (or maybe using another platform altogether).
The purpose of the spreadsheet is to help create schedules for an organization (a Toastmasters club). This organization has a roster of members, it meets weekly, and various members are assigned to various roles in a given meeting.
My spreadsheet looks like this:
First Tab
One column... a list of names representing the membership roster.
Second Tab
Each row represents a past meeting date. There are columns for each role, and the cells are to be populated with who served that role on that date. I use Data Validation to have the first tab's roster available inside each cell as a pulldown.
Third Tab (maybe multiple tabs?)
Here's the point of the whole thing. For each of the possible meeting roles, I would like to see which members are the most "overdue" to be assigned for that role. Basically, I want a list of all the club members, sorted in order of how long it's been since they last served that role. People who have never served in that role would be sorted at the top of the list.
Is that third tab data something that can be accomplished with a PivotTable, etc... or am I misunderstanding the purposes and limitations of those tools?
I found a way you can do this with pivot tableS - one per role. It's a bit dubious whether you should, but depends how many roles you have really. I made it work using 2 as a sample, here's the gist:
You have an (Excel) table containing Names
You have an (Excel) table containing Meeting Date, RoleA, RoleB... (I used Chair and Secretary as nominal examples), these cells contain the name of the person taking that role
You then create a Pivot Table for each role (Insert --> Pivot Table). The fields to use are: Row Labels - whichever role you're analysing; Values - Meeting Date
You then change the result type by going into Field Settings, and change it to Minimum. Note that only people who have had that role will show up here.
Repeat this for each role.
Go back to your table of names, and add a column for each role to show when they last held the role. The formula for this is the rather unwieldy:
=IFERROR(GETPIVOTDATA("Meeting Date",Chair!$A$3,"Chair",People[[#This Row],[Name]]),0)
The GETPIVOTDATA will error if they haven't had that role, so I'm replacing errors with 0 (an arbitrary low number)
You can then identify the person most overdue for the role using:
=OFFSET(People[[#Headers],[Name]],MATCH(MIN(People[LastChair]),People[LastChair],0),0)
If there is a tie, the person who appears first in your list of names will be given here.
Hope that makes some semblance of sense, ask away if any questions
My first instinct is to move you to Access where you can SQL query to your heart's content, but I'm sure this can be done in Access without any custom coding.
PivotTables may work, but I avoid them for several reasons (hard to describe to casual users, doesn't update automatically, hard to format, etc.), so here is something using just Excel's built-in cell functions.
Check out vlookup() and countif() on http://www.techonthenet.com/excel/formulas/index.php. (The built-in help files work too. I just like this site more)
In the image below, I have simulated your Tab2 and Tab3. Tab2 is purely data with no equations. Vlookup() requires that this table be sorted by Date Descending and with the date column on the far right.
Tab3 counts both the # times each person has served in that role and when they last worked that position.
The formula in cell C13 is =COUNTIF($B3:$B8,$B13). i.e. it counts the number of times that "Abe" appears in the Chairperson column of Tab2.
The formula in cell D13 is =IF(C13>0,VLOOKUP($B13,$B$2:$D$8,3,FALSE),"-"). i.e. if that person ever served in that role, then it finds the most recent date.
The formulas for security are almost the same. The "Last Served" column is now =IF(E13>0,VLOOKUP($B13,$C$2:$D$8,2,FALSE),"-"). The ranges need to be renamed here to satisfy the needs of the Vlookup function (a SQL query would be really convenient here, but Excel doesn't allow that)
It's hard to define if someone is 'overdue' because some people will argue that "Last Served" is more important than the "# Times Served" and others will argue the exact opposite. I suggest looking at both columns and just talking it over.