Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
AG3
Feb 4, 2004

Ask me about spending hundreds of dollars on Mass Effect 2 emoticons and Avatars.

Oven Wrangler
Is it possible to use vba to import a row from one sheet to another just by typing a specific number in a cell?

For example: I want to be able to type the number 150 or a text string like ABCD in a cell in Column A, and have Excel search a specific column in a different sheet for that string and then copy the contents of the row containing that string to the current row I'm typing in. I've tried googling this and I can't seem to find anything like this, or any commands that seem like they can do exactly this.

Adbot
ADBOT LOVES YOU

HootTheOwl
May 13, 2012

Hootin and shootin
You should be able to use the row number or column letter as an indexer on the row/column collection object property that a workbook has to access the specific row/column and then simply assign it to the row/column in the other workbook using the assignment operator. Or a for loop to iterate through the cells of the row column to copy each one individually


In this example, everything should be self explanitory.
sourceSheet is just the name of the sheet you're copying from.
destinationSheet where you're copying to.
destinationRow is the place you want your copied row to go. If you want to put it in the same place as the original sheet, change it to sourceRow
sourceRow is where you're copying from. as long as the user types a number in the cell you're looking at it can be as simple as:
code:
If Target.Row = 1 And Target.Column = 1 Then
Dim sourceRow As Integer
sourceRow = Target(1, 1).Value
I used the worksheet_selectionChange event to check if they typed in the special box (A1) and if they did, defined my source as equal to what they typed.

Iterating over that row to copy it will look like this:
code:
For Each littleCell In Worksheets(sourceSheet).Rows(sourceRow).Cells
    Worksheets(destinationSheet).Rows(destinationRow).Cells(littleCell.Column).Value = littleCell.Value
next

HootTheOwl fucked around with this message at 14:40 on Jan 18, 2023

Xerol
Jan 13, 2007


I have a sheet of data, which I am able to filter(unique()) on to get a list of names. I want each of these names to be repeated 3 times in the output, so e.g. if my formula is in A2 I want Data!A2 in A2, A3, A4; Data!A3 in A5, A6, A7, and so on. Is there any way to do this without macros/VBA?

e: Just putting the output in A2, A5, A8, and so on is also "good enough" for what I want this for.

Harminoff
Oct 24, 2005

👽

Xerol posted:

I have a sheet of data, which I am able to filter(unique()) on to get a list of names. I want each of these names to be repeated 3 times in the output, so e.g. if my formula is in A2 I want Data!A2 in A2, A3, A4; Data!A3 in A5, A6, A7, and so on. Is there any way to do this without macros/VBA?

e: Just putting the output in A2, A5, A8, and so on is also "good enough" for what I want this for.

I asked chatgpt exactly what you asked, and it returned this


=INDEX(Data!A:A, ROUNDUP(ROW()/3,0))

which does work. drat that tech is crazy.


quote:

I have a sheet of data, which I am able to filter(unique()) on to get a list of names. I want each of these names to be repeated 3 times in the output, so e.g. if my formula is in A2 I want Data!A2 in A2, A3, A4; Data!A3 in A5, A6, A7, and so on. Is there any way to do this with a formula?


quote:

Yes, you can use the INDEX and ROW functions in combination to repeat each name from your list 3 times in the output. Here is an example formula you can use:

=INDEX(Data!A:A, ROUNDUP(ROW()/3,0))

You would start by entering this formula in cell A2, then copy and paste it down the column for as many rows as you need. This formula uses the INDEX function to pull the value from the first column (A) of your Data sheet, and the ROW function to determine the current row number. The ROUNDUP function is used to divide the row number by 3 and round up to the nearest whole number, which results in each name being repeated 3 times in the output.

Lib and let die
Aug 26, 2004

Small Excel Questions Not Worth Being Answered by a Human

Harminoff
Oct 24, 2005

👽

Lib and let die posted:

Small Excel Questions Not Worth Being Answered by a Human

It's crazy how good it is, like just trying AG3's question gives working results.


quote:

Yes, it is possible to use VBA to accomplish this task. You can use the "Find" method to search for the specific number or text string in the specified column of the other sheet, and then use the "EntireRow" property to copy the contents of the entire row containing that string to the current row. Here is an example of how you can accomplish this using VBA:

Copy code
Sub ImportRow()
Dim searchString As String
Dim searchRange As Range
Dim foundCell As Range

searchString = ActiveCell.Value
Set searchRange = Sheets("Sheet2").Range("A:A")
Set foundCell = searchRange.Find(searchString)

If Not foundCell Is Nothing Then
foundCell.EntireRow.Copy ActiveCell.EntireRow
Else
MsgBox "The search string was not found."
End If
End Sub


You can call this subroutine in a worksheet's code-behind, for example, by using a command button to run the macro.



Of course, this one would need a little edit to see the other workbook instead of looking up the current one, but the code does work and is a good starting point.

Here is what I get by editing the quesiton a bit

quote:

Sub ImportRow()

'Declare variables
Dim wb1 As Workbook, wb2 As Workbook
Dim sh1 As Worksheet, sh2 As Worksheet
Dim searchValue As String
Dim searchRange As Range
Dim foundCell As Range

'Set the workbooks and worksheets
Set wb1 = ThisWorkbook 'The current workbook
Set wb2 = Workbooks("Book2.xlsx") 'The other workbook
Set sh1 = wb1.Sheets("Sheet1") 'The current sheet
Set sh2 = wb2.Sheets("Sheet1") 'The sheet in the other workbook to search

'Get the search value from cell A1 in the current sheet
searchValue = sh1.ActiveCell.Value

'Set the range to search in the other sheet
Set searchRange = sh2.Range("A:A")

'Search for the search value in the search range
Set foundCell = searchRange.Find(searchValue)

'Check if the search value was found
If Not foundCell Is Nothing Then
'Select the entire row of the found cell
foundCell.EntireRow.Select
'Copy the selected row
Selection.Copy
'Go to the current sheet and select the current row
sh1.Select
sh1.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Select
'Paste the copied row
Selection.PasteSpecial xlPasteValues
Else
'If the search value was not found, display a message
MsgBox "The search value was not found in the other sheet."
End If

End Sub

you could then use a shortcut and press that to bring the data over.

Harminoff fucked around with this message at 23:11 on Jan 24, 2023

HootTheOwl
May 13, 2012

Hootin and shootin
Chat GPT can read the MSDN just as good as anyone.
Except me, of course. I'm still worth the big bucks.

Toe Rag
Aug 29, 2005

Ask ChatGPT how to generate a Data Validation list based on the value of another cell.

DRINK ME
Jul 31, 2006
i cant fix avs like this because idk the bbcode - HTML IS BS MAN
That’s pretty neat but I’m not scared for my job as an “Excel guy” just yet, I work with people who don’t even realise you can just Google these questions so the chances of them asking gpt are pretty slim.

KOTEX GOD OF BLOOD
Jul 7, 2012

I'm kind of surprised to be struggling with this as it seems like a fairly straightforward thing, but none of the tutorials online seem to have an answer.

I have a list of expenses like this:

code:
Something Awful LLC	$420.69 
Something Awful LLC	$66.66 
Something Awful LLC	$69.69 
Ronco	$42.00 
Ronco	$33.33 
Bad Dragon Dildos, Inc.	$99.99 
Bad Dragon Dildos, Inc.	$0.99
I know how to make subtotals for each in the sheet itself, like this:

code:
Recipient	Amount
Something Awful LLC	$420.69 
Something Awful LLC	$66.66 
Something Awful LLC	$69.69 
Something Awful LLC Total	$557.04 
Ronco	$42.00 
Ronco	$33.33 
Ronco Total	$75.33 
Bad Dragon Dildos, Inc.	$99.99 
Bad Dragon Dildos, Inc.	$0.99 
Bad Dragon Dildos, Inc. Total	$100.98 
Grand Total	$733.35
But what I really want to do is have this all on a separate worksheet, in a Pivot Table I guess. Like so:

code:
Something Awful LLC Total	$557.04 
Ronco Total	$75.33 
Bad Dragon Dildos, Inc. Total	$100.98
Again, this seems like a straightforward thing, but I can't figure it out :smith:

Toe Rag
Aug 29, 2005

Wouldn't you literally just create a PivotTable with "Vendor" under "rows" and "Amount" under "values" with display as sum? Unless I am misunderstanding the question

HootTheOwl
May 13, 2012

Hootin and shootin

KOTEX GOD OF BLOOD posted:

I'm kind of surprised to be struggling with this as it seems like a fairly straightforward thing, but none of the tutorials online seem to have an answer.

I have a list of expenses like this:

code:
Something Awful LLC	$420.69 
Something Awful LLC	$66.66 
Something Awful LLC	$69.69 
Ronco	$42.00 
Ronco	$33.33 
Bad Dragon Dildos, Inc.	$99.99 
Bad Dragon Dildos, Inc.	$0.99
I know how to make subtotals for each in the sheet itself, like this:

code:
Recipient	Amount
Something Awful LLC	$420.69 
Something Awful LLC	$66.66 
Something Awful LLC	$69.69 
Something Awful LLC Total	$557.04 
Ronco	$42.00 
Ronco	$33.33 
Ronco Total	$75.33 
Bad Dragon Dildos, Inc.	$99.99 
Bad Dragon Dildos, Inc.	$0.99 
Bad Dragon Dildos, Inc. Total	$100.98 
Grand Total	$733.35
But what I really want to do is have this all on a separate worksheet, in a Pivot Table I guess. Like so:

code:
Something Awful LLC Total	$557.04 
Ronco Total	$75.33 
Bad Dragon Dildos, Inc. Total	$100.98
Again, this seems like a straightforward thing, but I can't figure it out :smith:

prefix any range or cell in the second worksheet with the name of the name of the first worksheet plus an exclimation point. So if you want column A from sheet 1 (named source):
code:
source!A:A
Also, when you go to insert->pivot table you're given the option to make your pivot table on a new worksheet.

KOTEX GOD OF BLOOD
Jul 7, 2012

Toe Rag posted:

Wouldn't you literally just create a PivotTable with "Vendor" under "rows" and "Amount" under "values" with display as sum? Unless I am misunderstanding the question


1. Yes 2. I am tired and stupid.

Thanks!

Busy Bee
Jul 13, 2004
I hope a Google Sheet question is okay here :)

I have a column in a Google Sheet where I copy and paste a date in YYYY-MM-DD format from the data we receive from the supplier. However, since we have many suppliers and thousands of rows of data, sometimes the date format they send to us is incorrect which messes up the automated data extraction.

What would be the best way to ensure that when the data is copy and pasted to have some sort of notification that the provided date format is incorrect? I was looking into conditional formatting but not sure if that would suffice.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Busy Bee posted:

I hope a Google Sheet question is okay here :)

I have a column in a Google Sheet where I copy and paste a date in YYYY-MM-DD format from the data we receive from the supplier. However, since we have many suppliers and thousands of rows of data, sometimes the date format they send to us is incorrect which messes up the automated data extraction.

What would be the best way to ensure that when the data is copy and pasted to have some sort of notification that the provided date format is incorrect? I was looking into conditional formatting but not sure if that would suffice.
I just realized after typing this all up that you might be asking for the date column to auto convert to YYYY-MM-DD...

If you're talking about where one field has the date as "2/2/2023" and another one has "Feb 2, 2024" and you want it formatted to YYYY-MM-DD. Click on the Column Header that has the Date field (so if it is Column B, click on the B in the sheet so that it highlights the entire column), After, go to Format|Number and choose "Custom date and time formats." By default it should already be using YYYY-MM-DD so just click Apply.

If you want to highlight invalid columns to show ones that Google could not format:

Go into your sheet, Click on Format|Conditional Formatting, and click on "Add another rule"
Under, "Apply to Range:" Specify, A1:<X>, where <X> is the last column in your sheet. If you have headers, use A2:<X>

So if you have 5 columns, where the last one ends in E, you would input "A1:E". If you have headers it would be, "A2:E"

Under Format Rules:
Under, "Format cells if...", Choose "Custom Formula is" at the very bottom.
In the Input Box underneath where it now says, "Custom Formula is" put in
code:
=AND($B2<>"", NOT(ISDATE($B2)))
Where B is the column your date is in, and 2 is if you have headers. If you don't have header use 1. Because your range is over multiple columns you must have that $ in there.

Choose a color in the Formatting Style (click on paint bucket or click on the header to choose Green/Yellow/Red

This will now highlight any rows that Google deems to be an "invalid" date.

------

AG3
Feb 4, 2004

Ask me about spending hundreds of dollars on Mass Effect 2 emoticons and Avatars.

Oven Wrangler

Harminoff posted:

It's crazy how good it is, like just trying AG3's question gives working results.

Of course, this one would need a little edit to see the other workbook instead of looking up the current one, but the code does work and is a good starting point.

Here is what I get by editing the quesiton a bit

you could then use a shortcut and press that to bring the data over.

Hey, after reading this I tried it myself, and I guess I phrased it differently because it gave me this code:

code:
Sub SearchAndCopy()
    Dim searchValue As Variant
    Dim searchRange As Range
    Dim foundRow As Range
    
    ' Get the search value from the active cell
    searchValue = ActiveCell.Value
    
    ' Set the search range to the first column of the sheet named "Data"
    Set searchRange = Worksheets("Data").Columns(1)
    
    ' Search for the value in the search range
    Set foundRow = searchRange.Find(What:=searchValue, LookIn:=xlValues, LookAt:=xlWhole)
    
    ' If the value is found, copy the row to the active sheet
    If Not foundRow Is Nothing Then
        foundRow.EntireRow.Copy
        ActiveCell.Offset(1, 0).EntireRow.Insert xlShiftDown
    Else
        MsgBox "Value not found in data sheet."
    End If
End Sub
It's not exactly what I wanted since I wanted to type the number in the field and then have it search for that number and copy the contents of the row, while this code looks up a number that has already been typed into the currently active cell and then copies the contents of that row into the row beneath the currently active cell. Still, it's amazing that it even worked, but I might be thinking that since I don't know VBA myself :v:

Harminoff
Oct 24, 2005

👽
Does this do what you are looking for? Put it in sheet1 instead of its own module.

I have two sheets, one called sheet1, and the other called data. Data has things like

123|tom|bob|roger

in sheet1, if I type 123 into cell a1, it will then become 123|tom|bob|roger

code:
Private Sub Worksheet_Change(ByVal Target As Range)

 

    If Target.Column = 1 Then
	Dim searchValue As Variant
	Dim searchRange As Range
	Dim foundRow As Range

	searchValue = Target.Value
	
	Set searchRange = Worksheets("Data").Columns(1)
	Set foundRow = searchRange.Find(what:=searchValue, LookIn:=xlValues, lookat:=xlWhole)

	If Not foundRow Is Nothing Then
		Application.EnableEvents = False
		foundRow.EntireRow.Copy Range(Target.Row & ":" & Target.Row)
		Application.EnableEvents = True
	End If
End If

End Sub

AG3
Feb 4, 2004

Ask me about spending hundreds of dollars on Mass Effect 2 emoticons and Avatars.

Oven Wrangler
It does, thank you very much!

Trivia
Feb 8, 2006

I'm an obtuse man,
so I'll try to be oblique.
Hi all. After a full day of searching and looking and watching I've finally thrown up my hands and decided to ask for help.

I've been tasked by my boss to see if I can come up with a spreadsheet that helps track maintenance for boat engine components. Each component needs to be changed or maintained after a certain threshold of use-hours, or elapsed time, whichever comes first.

I've got a basic idea of how the sheet should be laid out, as such:



As you can see, I'm using Google Sheets.

I've managed to figure out a few things on my own (I am a strict novice at programming). The idea is that the user inputs a boat's current use-hours and the date it was measured (under the boat name). Upon entry of the date the spreadsheet fires a script that stores the input hours and date as variables, then writes those to the last recorded hours field(s). The difference in use-hours and dates is then stored as well. I want to then use that difference and add it to each individual component's use-hours or elapsed time fields.

So, as an example with the above image, if I record the current hours as 40 and the date as the 20th of Feb, the script would then update all fields under each engine on that boat. The Engine Oil field would then show 50 (hours) and 22 (days).

The problem is that I can not for the life of me figure out how to use a script to add that script's variable's value to the current values of a range of cells (efficiently). I was playing around and managed to kinda make it work by making a bazillion variables, writing those to a separate sheet, and then using the setFormula function, but that was really really slow, both in the programming but also in the computation time. I know there's gotta be an easier way, I just don't know what I'm looking for.

Part of the reason I'm having so much difficulty is that a cell's formula field can't self-reference its current value and then add a script's variable to then spit out a new number (script variables are not global, so the spreadsheet doesn't know what its referencing). Instead I have to store each cell's current value as a variable in the script, add it to other variables, then output that new value into a sheet's cell so I can then use a formula function on the target cell. It's all very convoluted and time-consuming.

I suspect I'd need to pull the data range by odd/even rows, and then put it into an array. I'd then amend the array by the variable value and return to the sheet. I just have no idea how to do that. Or if that's even the best solution. Most of what I've found on Google and Youtube isn't helpful in that regard.

I hope what I've written makes sense. If any of you can tell me how to do it better or just point me in the right direction code-wise I'm sure I will eventually figure it out.

HootTheOwl
May 13, 2012

Hootin and shootin
I'm having trouble understanding what you want but a quick and dirty way to get around circular references is nice inputs to a different cell or worksheet all together.

Ninja.Bob
Mar 31, 2005

Trivia posted:

I hope what I've written makes sense. If any of you can tell me how to do it better or just point me in the right direction code-wise I'm sure I will eventually figure it out.

A couple of suggestions:
  • Use a javascript array to hold your variables rather than another sheet.
  • Try to do all your updating at once, rather than each cell one at a time. Apps script makes a call for each cell read or write, so if you can bundle it into a single setValues() instead of multiple setValue() it will be much quicker.
  • Use a custom number format for your items so they are numbers rather than strings: Format > Number > Custom Number Format > 0 "(hours)" / 0 "(days)" . This will make working with the cell data much easier.

Given your template, this is how I would approach it. I would define an array that contains the areas I am interested in for each boat. This gives you flexibility if you have boats with different numbers of engines or items, or you just want to change the sheet formatting. Then when a cell is updated, check to see if it's a current date cell for one of the boats and update that boat by reading and then writing all of its values at once.

JavaScript code:
const boats = [
  {
    "currentHours": "C3",
    "currentDate": "D3",
    "lastRecordedHours": "C4",
    "lastRecordedDate": "D4",
    "items": "B8:D53"
  },
  {
    "currentHours": "G3",
    "currentDate": "H3",
    "lastRecordedHours": "G4",
    "lastRecordedDate": "H4",
    "items": "F8:H53"
  },
];

// easy way to log errors as the execution log is unreliable for onEdit 
function log(spreadsheet, message) {
  const logSheet = spreadsheet.getSheetByName("Errors") || spreadsheet.insertSheet("Errors");
  logSheet.appendRow([new Date(), message] );
}

function onEdit(e) {
  const range = e.range;
  const editedCell = range.getA1Notation();
  const sheet = range.getSheet();

  try {
    
    boats.forEach(boat => {
      if(editedCell === boat.currentDate) {
        //calc deltas
        const currHours = sheet.getRange(boat.currentHours).getValue();
        const prevHours = sheet.getRange(boat.lastRecordedHours).getValue();
        const hours = currHours - prevHours;

        const currDate = sheet.getRange(boat.currentDate).getValue();
        const prevDate = sheet.getRange(boat.lastRecordedDate).getValue();
        const days = (currDate - prevDate) / 86400000; // milliseconds in 1 day
        
        // update last recorded fields and reset current fields
        sheet.getRange(boat.lastRecordedHours).setValue(currHours);
        sheet.getRange(boat.lastRecordedDate).setValue(currDate);
        sheet.getRange(boat.currentHours).setValue("");
        sheet.getRange(boat.currentDate).setValue("");

        // update the cells in the boats items.
        // collect all the values and set them all at once.
        const itemRange = sheet.getRange(boat.items);        
        const values = itemRange.getValues();
        
        for(let r = 0; r < values.length;r+=2) {
          for(let c = 0; c < values[r].length; c+=1) {
            values[r][c] += hours;
            values[r+1][c] += days;
          }
        }
        itemRange.setValues(values);
      }

    });
  } 
  catch (error) {
    log(e.range.getSheet().getParent(), error.message);
  }
}

Trivia
Feb 8, 2006

I'm an obtuse man,
so I'll try to be oblique.
Thanks for the help all, and sorry for my lovely technical writing lol

I'll pore over Ninja.Bob's post and see if I can't figure out what the hell it means.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Is there any uglier language than DAX? Survey says: no.

DRINK ME
Jul 31, 2006
i cant fix avs like this because idk the bbcode - HTML IS BS MAN
I’ve just been using DAX for a couple of weeks in power bi and it’s ain’t fun.

I started with calculated columns trying to do things, but I ended up with a single measure that does the currency conversion and displays the right segments using selecteditem() values.
It works but it was a hell of a journey to get there.

Hughmoris
Apr 21, 2007
Let's go to the abyss!

DRINK ME posted:

I’ve just been using DAX for a couple of weeks in power bi and it’s ain’t fun.

I started with calculated columns trying to do things, but I ended up with a single measure that does the currency conversion and displays the right segments using selecteditem() values.
It works but it was a hell of a journey to get there.

I have zero affiliation with these guys but I've found their free "Intro to Dax" course to be pretty approachable:

https://www.sqlbi.com/training/

I always found an online DAX repl which I've been poking about with.

DRINK ME
Jul 31, 2006
i cant fix avs like this because idk the bbcode - HTML IS BS MAN
Thanks

We have a bunch of free internal training on every topic through some subscription service so I’d probably have some dax stuff in there as well. I’ve just been stealing stuff from the powerbi forums and stackexchange to get it to work.

Reminded me that I need to quickly run through either a Power Apps or Power Automate training before the end of month to meet my learning KPI for the year - can’t recall which it was because the bosses boss chose that for me, 8 months into the financial year, and I haven’t looked at it yet.

double nine
Aug 8, 2013

is there conditional formatting formula that allows for

- highlighting odd cells (i.e. ignore every other row)
- only if those cell values are less than 2

at the same time?

I can't find a way to combine ODD(ROW())=ROW() with a logical function that checks the cell contents for the value > 2

HootTheOwl
May 13, 2012

Hootin and shootin

double nine posted:

is there conditional formatting formula that allows for

- highlighting odd cells (i.e. ignore every other row)
- only if those cell values are less than 2

at the same time?

I can't find a way to combine ODD(ROW())=ROW() with a logical function that checks the cell contents for the value > 2

Use modulo division on the row number:
code:
 =MOD(ROW(),2)=1
Modulo division returns the remainder instead of the quotient, so all even number cells will equal 0 when you divide by 2 and all odd numbered ones will equal 1

Shazback
Jan 26, 2013

double nine posted:

is there conditional formatting formula that allows for

- highlighting odd cells (i.e. ignore every other row)
- only if those cell values are less than 2

at the same time?

I can't find a way to combine ODD(ROW())=ROW() with a logical function that checks the cell contents for the value > 2

For example from row E4:

= And( modulo( Row(E4) , 2 ) , E4 > 2 )

double nine
Aug 8, 2013

ty

Looten Plunder
Jul 11, 2006
Grimey Drawer
This is a pivot table question. I'd be happy to have this answered from an Excel perspective and figure out how to reproduce it i Sheets/Looker at a later date. Copy and pasting my question from Reddit:

I work in a call centre. I'm trying to create a dashboard in Google Looker for displaying agent quality performance. I'm having trouble getting pivot table to do what I want it to do, and also have a follow up question about drill downs (but knowing that this is the Google Sheets sub, i'll focus my question on the pivot table). Here is my framework:

-Agents get given a rating on a bunch of questions. These are 5 item scale (Bad, Average, Good, Very Good etc.)
-Every evaluation that gets completed has it's own line on a report. It ends up looking something like this
-There is correspondending commentary to justify the marking of each question, resulting in a column for each question and column for each questions commentary. Something like this
-I created a summary that looks like this to quickly identify areas of improvement. To do this I created extra columns to give the answer to each question a numerical value eg. =IF(CELL="Bad","1"), Good=2, VeryGood=3 etc.

Ideally, I'd like to be able to double click on a cell in that chart, for example the top left one being James Baker/Acknowledgment and it would drill down/go to another chart/table that shows a filtered view of all the comments for Acknowledgement that contributed to James Baker's rating.

An alternative display is that I'd like a pivot table (or a 100% stacked bar chart) that displays the "Question" on the X-axis/columns and the "Rating" (good, bad etc.) as the Y-Axis/Row/Breakdown of the bar. But I don't know how to get "Rating" answers to display as the colums. I want it to look something like this in pivot table form or this in bar chart form from which i'd be able to double click any of those cells/colour blocks and it would take me to the commentary for that entry

So in summary, my questions are:

-With my data structured like it is, how do I create a pivot table to show "Question" as the column, "Rating" as the row and number of times that rating was given for each question as the data?
-How do I create a bar chart to do the same?
-Is it possible to attribute a numberic value to a text string so I can avoid the "create additional columns and lookup the value of another column to give it a number" step in the process?
-Do i have the abiility to drill down to see the commentary for the associated question ratings?

Hope this is clear, any help would be appreciated

HootTheOwl
May 13, 2012

Hootin and shootin

Looten Plunder posted:

-Is it possible to attribute a numberic value to a text string so I can avoid the "create additional columns and lookup the value of another column to give it a number" step in the process?
https://support.microsoft.com/en-us/office/lambda-function-bd212d27-1cd1-4321-a34a-ccbf254b8b67
Do this first and then follow this page and you should be fine.
https://superuser.com/questions/1084075/how-to-generate-an-excel-chart-that-includes-aggregating-and-grouping

HootTheOwl fucked around with this message at 13:32 on Apr 28, 2023

FreshFeesh
Jun 3, 2007

Drum Solo
I would like to average all numbers where any of the following columns contain particular words, but my use of AVERAGEIF was giving me results that were way off (divide by zero errors, answers 1/4th expected values, et cetera). Is there a reasonable/rational way to match/average values based on the contents of multiple columns?

Sample Data:
code:
Number	Result
----------------------------
119	Re-test			
107	Pass	  2nd Pass	Re-test	
185	Re-test	  Rejected
135	Re-test			
175	Pass	  2nd Pass	3rd Pass	4th Pass
375	Pass	  Rejected		
189	Rejected
207	Re-test	  Pass 
Desired Output:
code:
Result		Average
----------------------------
Pass		216
2nd Pass	141
3rd Pass	175
Re-test		144
Rejected	250
It is intentional that if something matches multiple states (Pass, Rejected, whatnot) that the entry gets added into the average for each discrete result

esquilax
Jan 3, 2003

FreshFeesh posted:

I would like to average all numbers where any of the following columns contain particular words, but my use of AVERAGEIF was giving me results that were way off (divide by zero errors, answers 1/4th expected values, et cetera). Is there a reasonable/rational way to match/average values based on the contents of multiple columns?

Sample Data:
code:
Number	Result
----------------------------
119	Re-test			
107	Pass	  2nd Pass	Re-test	
185	Re-test	  Rejected
135	Re-test			
175	Pass	  2nd Pass	3rd Pass	4th Pass
375	Pass	  Rejected		
189	Rejected
207	Re-test	  Pass 
Desired Output:
code:
Result		Average
----------------------------
Pass		216
2nd Pass	141
3rd Pass	175
Re-test		144
Rejected	250
It is intentional that if something matches multiple states (Pass, Rejected, whatnot) that the entry gets added into the average for each discrete result

In general, instead of AVERAGEIF you are probably better off doing a SUMIF divided by a COUNTIF. Does this solve your problem? It should only return a Div/0 error when you try to average a Result that doesn't exist in the data.

There are other ways that are a little more scalable but this is probably simplest with what you have already built.

HootTheOwl
May 13, 2012

Hootin and shootin

FreshFeesh posted:

I would like to average all numbers where any of the following columns contain particular words, but my use of AVERAGEIF was giving me results that were way off (divide by zero errors, answers 1/4th expected values, et cetera). Is there a reasonable/rational way to match/average values based on the contents of multiple columns?

Sample Data:
code:
Number	Result
----------------------------
119	Re-test			
107	Pass	  2nd Pass	Re-test	
185	Re-test	  Rejected
135	Re-test			
175	Pass	  2nd Pass	3rd Pass	4th Pass
375	Pass	  Rejected		
189	Rejected
207	Re-test	  Pass 
Desired Output:
code:
Result		Average
----------------------------
Pass		216
2nd Pass	141
3rd Pass	175
Re-test		144
Rejected	250
It is intentional that if something matches multiple states (Pass, Rejected, whatnot) that the entry gets added into the average for each discrete result

Your problem is that SUMIF doesn't like spanning across multiple columns for the if clause, and that SUMIFS only does the logical AND
Thankfully this doesn't happen to Countif, it instead has a problem where you can't do "Countif(A:E)" so you havbe to provide bounds
So the answer is:
code:
=(SUMIF(B:B,"pass",A:A)+SUMIF(C:C,"pass",A:A)+SUMIF(D:D,"pass",A:A)+SUMIF(E:E,"pass",A:A))/COUNTIF(B1:E100, "pass")
find/replace as nessessary

FreshFeesh
Jun 3, 2007

Drum Solo

esquilax posted:

In general, instead of AVERAGEIF you are probably better off doing a SUMIF divided by a COUNTIF. Does this solve your problem? It should only return a Div/0 error when you try to average a Result that doesn't exist in the data.

There are other ways that are a little more scalable but this is probably simplest with what you have already built.


Unfortunately SUMIF provides weird results too when I call it across a range of columns.

In this example I would expect the answer to be 0, as the only line which contains the target text doesn't have a value in the sum field

code:
A	B	C		D
----------------------------------------------
NULL	Pass	2nd Pass	Timed Out

=SUMIF(B:D,"Timed Out",A:A)
44.998
Edit: Thanks for the deep dive, HootTheOwl. I'll give that a go

esquilax
Jan 3, 2003

FreshFeesh posted:

Unfortunately SUMIF provides weird results too when I call it across a range of columns.

In this example I would expect the answer to be 0, as the only line which contains the target text doesn't have a value in the sum field

code:
A	B	C		D
----------------------------------------------
NULL	Pass	2nd Pass	Timed Out

=SUMIF(B:D,"Timed Out",A:A)
44.998
Edit: Thanks for the deep dive, HootTheOwl. I'll give that a go

Oh, I was assuming you were already using a formula for each column on your AVERAGEIF functions the way that HootTheOwl is suggesting that you do. Yeah neither AVERAGEIF or SUMIF play nicely wth a criteria array that is a different size than the sum array.

FreshFeesh
Jun 3, 2007

Drum Solo
I genuinely appreciate the help, but as is so often the case I ran into another issue.

The above approach (SUMIF/COUNTIF) works just fine for entries which contain all the data, but some rows lack the "Number" column (an example of which I should have included in my initial post), which means the averages [of entries with a value] get thrown way off.

Because COUNTIFS has issue with ranges of differing sizes (e.g. I can't do a countifs for descriptor in columns B:D with a check for notblank in column A) I'm unable to make a simple tweak to the above formulae to make it work.

My goal is to get an average of all cells that match the descriptor AND have a value in column A, if that makes sense.

HootTheOwl
May 13, 2012

Hootin and shootin

FreshFeesh posted:

I genuinely appreciate the help, but as is so often the case I ran into another issue.

The above approach (SUMIF/COUNTIF) works just fine for entries which contain all the data, but some rows lack the "Number" column (an example of which I should have included in my initial post), which means the averages [of entries with a value] get thrown way off.

Because COUNTIFS has issue with ranges of differing sizes (e.g. I can't do a countifs for descriptor in columns B:D with a check for notblank in column A) I'm unable to make a simple tweak to the above formulae to make it work.

My goal is to get an average of all cells that match the descriptor AND have a value in column A, if that makes sense.

You're going to need to do something you did for the sum of countifs, here:
code:
=COUNTIFS(B:B, "pass", A:A, ">0") + COUNTIFS(C:C, "pass", A:A, ">0")
Counting each thing in column X where the words equal what you want AND where the first column has a value greater than 0

HootTheOwl fucked around with this message at 17:58 on May 4, 2023

Adbot
ADBOT LOVES YOU

Fingerless Gloves
May 21, 2011

... aaand also go away and don't come back
Could you concatenate the test results into one column and just run the averageif using text search criteria, like "*re-test*"?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply