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
Remora
Aug 15, 2010

Hey excel thread - is there any way to export the formatting of a .xlsx to VBA code (".Range("A5").Font.Bold = True" etc)? Basically I have an intricately formatted report that I am automating in Access, but manually specifying every single piece of this spreadsheet will take hours - any way to automate that process would be incredibly helpful.

Adbot
ADBOT LOVES YOU

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Remora posted:

Hey excel thread - is there any way to export the formatting of a .xlsx to VBA code (".Range("A5").Font.Bold = True" etc)? Basically I have an intricately formatted report that I am automating in Access, but manually specifying every single piece of this spreadsheet will take hours - any way to automate that process would be incredibly helpful.

It might not be exactly what you want (I have no idea on that, not a VBA user) but couldn't you do the HTML format to at least get font/colour/etc information and then do something with that? I could see regex being helpful there.

mystes
May 31, 2006

There's probably not going to be a good way but what are you trying to do with the formatting specifically?

mystes fucked around with this message at 03:47 on Dec 7, 2018

Remora
Aug 15, 2010

I need to exactly match the appearance of this legacy report that was previously done by hand from an Excel template, because people are scared of change. I have an Access database that can do all the number crap, but if it looks different people won't use it, because people are scared of change (and dumb). It's got merged cells and panes and tons of color-coding and crap. I can just code it all into VBA by hand, but that is going to suuuuuuuuck.

mystes
May 31, 2006

Remora posted:

I need to exactly match the appearance of this legacy report that was previously done by hand from an Excel template, because people are scared of change. I have an Access database that can do all the number crap, but if it looks different people won't use it, because people are scared of change (and dumb). It's got merged cells and panes and tons of color-coding and crap. I can just code it all into VBA by hand, but that is going to suuuuuuuuck.
I mean what are you matching it in? An access report? Or are you generating Excel files? If excel files can't you just copy the values into the template?

Remora
Aug 15, 2010

Generating an excel file using VBA. I have to bake it all into the database itself, I can't rely on the end user to have the template on hand as a long term solution - is there a way to stuff an excel template into Access? I can probably limp along with that for the next few weeks, though, I suppose.

mystes
May 31, 2006

Remora posted:

Generating an excel file using VBA. I have to bake it all into the database itself, I can't rely on the end user to have the template on hand as a long term solution - is there a way to stuff an excel template into Access? I can probably limp along with that for the next few weeks, though, I suppose.
Make a new table with an attachment field and put one row in it that has the template?

Testikles
Feb 22, 2009

AzureSkys posted:

I have a spreadsheet my group uses to keep track of a product number, the date it starts, the date it finishes, and the location it’s made at. We use this to keep track of who’s assigned which product number at which location. There are multiple sources for the start and finish dates along with location and we’ve been looking at those (usually a PDF) and manually putting those dates and names in our spreadsheet, which gets tedious and easy to mistype. The dates and location can change daily or get assigned for the 100 or so product numbers that are needed on the assignment sheet.

I’ve recently found a data source that I can give me a csv extract. It lists every date that the product is in work, 3 to 5 days, but I only need the start and finish dates.
I’ve figured out a vlookup and sum formula to get the start and end date OK as well as the location for each product number, but there’s a twist.

The schedule only lists things that are today and on. I still need to keep the date for things that have passed since my assignment sheet needs to show them. I cannot figure out how to have a formula look up the product numbers start and end date as well as leave the dates unchanged if prior to today after I update the cvs extract. The location part is easy enough to use with vlookup, so that's not an issue.

This is my formula I found somewhere for getting the start and finish dates. Schedule is the sheet with the CSV extract, column C on my assignment sheet is the product number which is unique to each product and is also column S on Schedule, and Schedule column X is the dates:

code:
=IF(SUM(IF(Schedule!$S:$S=$C4,Schedule!X:X))=0,"",MIN(IF(Schedule!$S:$S=$C4,IF(ISNUMBER(Schedule!$X:$X),Schedule!$X:$X))))
=IF(SUM(IF(Schedule!$S:$S=$C4,Schedule!X:X))=0,"",MAX(IF(Schedule!$S:$S=$C4,IF(ISNUMBER(Schedule!$X:$X),Schedule!$X:$X))))
In the end it looks like this, but when I update the next days schedule changes anything that's not today's date and on will be blank:
code:
Product #	Start		Finish		Location
1053		11/21/2018	11/26/2018	North
1054		11/22/2018	11/25/2018	South
1055		11/26/2018	11/29/2018	South
1056		11/27/2018	11/30/2018	North
1057		11/30/2018	12/03/2018	North
I don't need it all in one formula, though that would be nice. I keep failing with trying different IF statements when I break up the different steps since I'm a bit of an excel newbie. What I've been doing is just finding the info on a separate sheet by first sorting the start times on the assignment sheet and then grabbing the product numbers of ones with today's date and on to then use for the on the schedule lookup. I have to then paste in the date/location changes back to the assignment sheet which can potentially be miss aligned. It works, but before I pass this on to others to do I want to simplify it as much as possible.

If I'm understanding you right, you want a sheet that reads the .csv and updates the start date and end date?

So if you have product A, if you paste in the .csv somewhere, the formula knows to check that row for product A and list the most recent date as the end, and the oldest as start?

AzureSkys
Apr 27, 2003

Testikles posted:

If I'm understanding you right, you want a sheet that reads the .csv and updates the start date and end date?

So if you have product A, if you paste in the .csv somewhere, the formula knows to check that row for product A and list the most recent date as the end, and the oldest as start?

Yes. I have them linked by the product number that both my schedule and the .csv will already have listed. What I'd like is for my schedule sheet to read the .csv and pull the start date for the applicable product number (which is the first date in the .csv data extract) into one cell and the finish date (which is the last date in the extract) as well as the location which is easy to do.

But, if the dates are older than today they end up blank since the .csv only has dates from today and on. There may be a product that started a few days prior and just finished, but still needs to be on the assignment sheet for other purposes. I'd like them to stay with whatever the last date was if it is prior to today, if that makes sense. That would fully automate the process so others who are less savvy can just grab the daily .csv extract, update the data link and everything will go from there.

The .csv looks like this more or less:
code:
.csv schedule data extract
Product #	Date		Location
1053		11/21/2018	North
1053		11/22/2018	North
1053		11/23/2018	North
1053		11/24/2018	North
1053		11/25/2018	North
1053		11/26/2018	North
1054		11/22/2018	South
1054		11/23/2018	South
1054		11/24/2018	South
1054		11/25/2018	South
1055		11/26/2018	South
1055		11/27/2018	South
1055		11/28/2018	South
1055		11/29/2018	South
1056		11/26/2018	North
1056		11/27/2018	North
1056		11/30/2018	North
1057		11/30/2018	North
1057		12/1/2018	North
1057		12/2/2018	North
1057		12/3/2018	North
The formula I ended up with does OK at giving the start and end date for a given product number OK like my previous example showed:
code:
Assignment sheet
Product #	Start		Finish		Location
1053		11/21/2018	11/26/2018	North
1054		11/22/2018	11/25/2018	South
1055		11/26/2018	11/29/2018	South
1056		11/27/2018	11/30/2018	North
1057		11/30/2018	12/03/2018	North
I'm not sure how to handle the need to keep dates unchanged if they're prior to today's date when the .csv is obtained for each days changes and only shows dates today and beyond.

So if today is 11/23/2018, product 1053 would still be in process but the start date listed on my assignment sheet would show 11/23/2018 instead of it's actual start date of 11/21/2018 . If it was after the finish date for that product, like 11/27/18 and 1053 was still needed on the assignment sheet both dates would then be blank instead of remaining 11/21/2018 and 11/26/2018 since it would no longer show it on the .csv schedule. I have no clue if that's even possible to do, though.

Testikles
Feb 22, 2009
What would really be the best imo is writing a macro in VBA that will read the csv and print the most recent date and oldest date to your sheet. The problem might be too complicated for formulas as is. Do you have any experience writing stuff like that or is it all just formulas?

AzureSkys
Apr 27, 2003

I haven't done anything much with VBA other then edit some macros. Things will be slower at work so I'll more time to try to learn some.

Kibayasu
Mar 28, 2010

Hi Excel thread, I don’t have a question because the shame and annoyance of having to come here and ask a question gave me the motivation to figure out the incredibly obvious solution I was overlooking while I was typing the question.

Thanks Excel thread!

Kibayasu
Mar 28, 2010

Ok, I lied, I do have a question though one that's about convenience more than anything else.

I have a a worksheet that contains a master list of file names and their corresponding name in our accounting software arranged as such:

code:
File Name                 Vendor Name
Customer 1.xlxs           Customer 1 Vendor Name
Customer 2.xlxs           Customer 2 Vendor Name
Customer 3.xlxs           Customer 3 Vendor Name
And so on.

On another worksheet I'm creating another list that some third party software will look at and export data from those customers' files into the accounting software. The convenience issue I'm running into is that for the third party software to work every account to be exported to the accounting software needs its own row (10 accounts, so 10 row each), like this:

code:
Vendor Name              Account        Amount
Customer 1 Vendor Name   Expense 1      $
Customer 1 Vendor Name   Expense 2      $$
Customer 1 Vendor Name   Expense 3      $$$
...
Customer 1 Vendor Name   Expense 10     $$$$$$$$$$
So on the master list each customer takes up 1 row but on the export sheet each customer takes up 10 rows, meaning that I can't just copy/paste formulas all the way down on the export worksheet because that would look like this at the end of the first account and the beginning of the second.

code:
Vendor Name              Account        Amount
='Master List'!A10       Expense 10     $$$$$$$$$$
='Master List'!A20       Expense 1      $
I could solve this by having each customer on the master list take up 10 rows, which would change the references to the master list to:

code:
Vendor Name              Account        Amount
='Master List'!A10       Expense 1      $
='Master List'!A11       Expense 2      $$
='Master List'!A12       Expense 3      $$$
...
='Master List'!A19       Expense 10     $$$$$$$$$$
='Master List'!A20       Expense 1      $
I could also have each customer on the master list have 9 blank rows below each of them which would make the third from top [code] segment up there work.

I'm just wondering if there's a way to just... not do either of those? Keep the master list worksheet as it is (one customer per row, no repeating or blank cells), keep the export worksheet as it is (10 rows for each customer), and be able to auto-fill the Vendor Name column on the export worksheet?

Edit: In short, have the auto fill on the export worksheet only move down one row reference to the master list worksheet despite the export worksheet moving down 10 rows before referencing the next master list row.

Kibayasu fucked around with this message at 00:18 on Dec 30, 2018

Ninja.Bob
Mar 31, 2005
If you want more control over which rows in one range match to rows (or columns) in another, generally you use the INDEX function. The ROW function will give you your current row number and to compress 10 rows into one just divide by 10 and take the FLOOR or CEILING. Adding and subtracting before the division and after the ceiling allows you to offset the rows in the source and target ranges. In this case using ceiling is easier than floor because it will map 1 - 10 > 1 rather than 0 - 9 > 0 and is generally easier to reason about.

code:
Vendor Name                                                  Account        Amount
=INDEX('Master List'!$A$2:$A$100,CEILING((ROW()-1)/10,1))    Expense 1      $
=INDEX('Master List'!$A$2:$A$100,CEILING((ROW()-1)/10,1))    Expense 2      $$
=INDEX('Master List'!$A$2:$A$100,CEILING((ROW()-1)/10,1))    Expense 3      $$$
In this case the number of header rows in the sheet is 1 (ROW()-1) and the number of times you want each row repeated is 10. If the range you are indexing into includes headers add the number to the ceiling (e.g. 1+CEILING ...). You don't need to provide a column number for the index function but you can if you need it.

Kibayasu
Mar 28, 2010

Ninja.Bob posted:

If you want more control over which rows in one range match to rows (or columns) in another, generally you use the INDEX function. The ROW function will give you your current row number and to compress 10 rows into one just divide by 10 and take the FLOOR or CEILING. Adding and subtracting before the division and after the ceiling allows you to offset the rows in the source and target ranges. In this case using ceiling is easier than floor because it will map 1 - 10 > 1 rather than 0 - 9 > 0 and is generally easier to reason about.

code:
Vendor Name                                                  Account        Amount
=INDEX('Master List'!$A$2:$A$100,CEILING((ROW()-1)/10,1))    Expense 1      $
=INDEX('Master List'!$A$2:$A$100,CEILING((ROW()-1)/10,1))    Expense 2      $$
=INDEX('Master List'!$A$2:$A$100,CEILING((ROW()-1)/10,1))    Expense 3      $$$
In this case the number of header rows in the sheet is 1 (ROW()-1) and the number of times you want each row repeated is 10. If the range you are indexing into includes headers add the number to the ceiling (e.g. 1+CEILING ...). You don't need to provide a column number for the index function but you can if you need it.

Thanks a lot. I'm still not sure if I understand exactly what this is doing but once I changed your ROW()-1 to ROW()-10 it worked exactly as I needed it to. By header rows did you mean any rows before the start of the actual list on either sheet? In my case the master list sheet started on Row 10 and the export sheet starts on Row 20 so that may have something to do with it?

And just to note an oddity I took note of after your solution worked, I accidentally stopped autofill one row further down than I should have when I was testing it. Since I need 10 rows for every customer I select Rows 20-29 and fill down to Row 39. This worked perfectly, but on the next test (Row 40-49) I stopped on Row 50 by mistake. Row 50 filled out with the next name on the list it should have but when I continued filling down the next row (51) immediately switched to the next name in the master list, the customer that was below the one in Row 50. I hadn't reselected the autofill range or anything either. Now I should be always stopping on a Row ending with 9 anyways so this isn't really a problem that needs to be fixed (and "filling" back up to the row I should have stopped on fixes the issue if I needed to continue to fill down) but I just thought I'd mention it.

Anyways as long as use it on the correct number of rows it works great :waycool: Thanks!

Kibayasu fucked around with this message at 19:36 on Dec 30, 2018

Ninja.Bob
Mar 31, 2005
If you aren't exactly sure how the formula works, you can use the Evaluate formula tool under Formulas > Formula Auditing to see it broken down step by step. You understood correctly what I meant by header rows.

If the first row of actual data in the export sheet is row 20 then you would want ROW()-19, as ROW()-19 = 1. If the data in the 'Master List' sheet starts at row 10 then the index range should be 'Master List'!$A10$A$.... So the final formula would be =INDEX('Master List'!$A$10:$A$1000,CEILING((ROW()-19)/10,1)). This will then get the customer name from row 10 in the master list for export rows 20 - 29, 11 > 30 - 39, etc.

If you are getting different results from auto filling up vs down then there is definitely an error. The formula should be identical in each row so make sure that you are using an absolute range that doesn't change as you copy it. The other common source of error is changing the first row but forgetting to update the rest and then copying them as a block to end up with a different formula every 10 rows. This can be hidden in this scenario because it might take a few customers before the error grows large enough for the result to be wrong.

Kibayasu
Mar 28, 2010

I mean I autofilled all 288 (so 2880 cells) without an error (except if I autofilled/pasted to the wrong cell) so... :shrug:

I’ll look at it again next chance I get.

Kibayasu
Mar 28, 2010

Ninja.Bob posted:

If you aren't exactly sure how the formula works, you can use the Evaluate formula tool under Formulas > Formula Auditing to see it broken down step by step. You understood correctly what I meant by header rows.

If the first row of actual data in the export sheet is row 20 then you would want ROW()-19, as ROW()-19 = 1. If the data in the 'Master List' sheet starts at row 10 then the index range should be 'Master List'!$A10$A$.... So the final formula would be =INDEX('Master List'!$A$10:$A$1000,CEILING((ROW()-19)/10,1)). This will then get the customer name from row 10 in the master list for export rows 20 - 29, 11 > 30 - 39, etc.

If you are getting different results from auto filling up vs down then there is definitely an error. The formula should be identical in each row so make sure that you are using an absolute range that doesn't change as you copy it. The other common source of error is changing the first row but forgetting to update the rest and then copying them as a block to end up with a different formula every 10 rows. This can be hidden in this scenario because it might take a few customers before the error grows large enough for the result to be wrong.

Right, so to satisfy whatever curiosity this might have generated there was indeed an error but I was also mindlessly repeating what I was doing to test the results of my previous attempts despite saying I was only using autofill. But because I repeated what I was doing to test the results before using autofill on the rest of the sheet it resulted in the correct answer.

CEILING((ROW()-10)/10,1) worked because when I was trying various other methods myself I had set the 9 cells below each first cell to equal the cell above it until the start of the next 10 rows. So after putting in your code it looked like:

code:
=INDEX('Master List'!$A$10:$A$2010,CEILING((ROW()-10)/10,1))
=A20
=A21
=A22
=A23
=A24
=A25
=A26
=A27
=A28
=INDEX('Master List'!$A$10:$A$2010,CEILING((ROW()-10)/10,1))
=A30
But instead of auto filling down from the very first cell and immediately seeing the problem I repeated what I was doing to test results from my latest attempt before I asked here, which was copy/pasting the first 10 rows into the next 10 rows to test. So it didn't matter that the result in the 9 cells after the first cell were wrong - and after putting =CEILING(ROW()-10)/10,1) into its own column I could see that they were - because the first row of every 10 cells had the correct result.

code:
Customer       Cell    Function                    Result
Customer 1*    A20     CEILING((ROW()-10)/10,1)    1*
Customer 1     A21     CEILING((ROW()-10)/10,1)    2
Customer 1     A22     CEILING((ROW()-10)/10,1)    2
Customer 1     A23     CEILING((ROW()-10)/10,1)    2
Customer 1     A24     CEILING((ROW()-10)/10,1)    2
Customer 1     A25     CEILING((ROW()-10)/10,1)    2
Customer 1     A26     CEILING((ROW()-10)/10,1)    2
Customer 1     A27     CEILING((ROW()-10)/10,1)    2
Customer 1     A28     CEILING((ROW()-10)/10,1)    2
Customer 1     A29     CEILING((ROW()-10)/10,1)    2
Customer 2*    A30     CEILING((ROW()-10)/10,1)    2*
Customer 2     A31     CEILING((ROW()-10)/10,1)    3
So the first cell for Customer 1 is right, everything else is wrong. The first cell for Customer 2 is right, everything else is wrong. But since the function for the next 9 cells were just to look at the result of the one above it it didn't matter.

CEILING(ROW()-19)/10,1) of course works for every cell without the need to =A20, =A21, etc.

Thank you again.

nickhimself
Jul 16, 2007

I GIVE YOU MY INFO YOU LOG IN AND PUT IN BUILD I PAY YOU 3 BLESSINGS
never mind

nickhimself fucked around with this message at 21:14 on Jan 22, 2019

nickhimself
Jul 16, 2007

I GIVE YOU MY INFO YOU LOG IN AND PUT IN BUILD I PAY YOU 3 BLESSINGS
Sorry for the double post, but it turns out I actually do need help.

Here's what I'm doing. In this leasing worksheet I've coded a button that will import an old deal and convert it all to the newer model. However, I'm stumped with the last piece of the conversion puzzle.

Here's a clip of where I'm working inside of:


Those yellow lines often contain things like "Delivery $100.00" between columns A and B. However, the salesmen don't *always* add items. When they do, sometimes they'll add an entire row, other times they'll remove rows.

This is what I need:
Any lines in A11-13 that equal "Initial CC" need to be cleared, along with the associated cost in the next cell.


Any ideas?

edit: lol, I'm dumb. I thought about it for more than two seconds and figured it out.

Range("A1:B34").Select
Cells.Find(What:="Initial CC", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.ClearContents
ActiveCell.Offset(0, 1).ClearContents

nickhimself fucked around with this message at 15:55 on Jan 25, 2019

Busy Bee
Jul 13, 2004
Just received a new laptop at work with the latest version of Microsoft Office 365. My previous laptop had Microsoft Office 2013 installed and I had no problems opening CSV files with all the data formatted in the correct way – columns were all separated correctly.

However, I’m having issues now on my new laptop right when I open the CSV file for some reason – all the columns are stuck together. A correct fix that I found is unchecking “Use system separators” in the Advanced section of Excel options. When I uncheck that, all the columns and data is separated correctly but it also messes up the format of some of the variables such as the currency amount.

The CSV columns are formatted like this “data 1, data 2, data 3, data 4” etc.

How can I fix this? It doesn't fix it if I save the CSV as an Excel Workbook after opening it and I do not have an option to save the CSV files as an Excel Workbook when I download the workbook.

nielsm
Jun 1, 2009



Windows is probably configured to use comma as decimal separator, and period as thousands separator. (European style.) Change that in the international settings page where ever they have put it now.

Busy Bee
Jul 13, 2004

nielsm posted:

Windows is probably configured to use comma as decimal separator, and period as thousands separator. (European style.) Change that in the international settings page where ever they have put it now.

That worked, thank you!

nickhimself
Jul 16, 2007

I GIVE YOU MY INFO YOU LOG IN AND PUT IN BUILD I PAY YOU 3 BLESSINGS
I have a Customer Name search box that looks through a Last Name/Business Name list and returns the first matching result, plus the next subsequent seven below it in alphabetical order.

However, a bug has been found and I don't know how to google the answer.

The macro currently begins by first selecting the top cell in the column, then combing the list for the first matching term. If I don't do that I run into other sorting issues unrelated to this.

If I search for "Smith" it will return something like "Jeff Smith Corp, Inc." instead of finding the first "Smith" name down in the S range. How can I make it search from the beginning of the word first? Is that possible?

DRINK ME
Jul 31, 2006
i cant fix avs like this because idk the bbcode - HTML IS BS MAN
Without being sure how the macro is working, something like LEFT(cell, LEN(search_string)) maybe.

So if it’s doing a loop through the cells like:
Find(search_string, cell)
You could change this to be:
Find(search_string, Left(cell, Len(search_string)))

This would only find where Smith is at the start of the entry. You may have issues with entries starting with “The” though, depending on your data and your searches.

nickhimself
Jul 16, 2007

I GIVE YOU MY INFO YOU LOG IN AND PUT IN BUILD I PAY YOU 3 BLESSINGS
I'll give that a shot and see if it does what I need. If not, I'll be back with more problems, lol


Thank you!!

nickhimself fucked around with this message at 12:57 on Jan 31, 2019

Harminoff
Oct 24, 2005

👽
I have a few users that work in duplicate worksheets but different data sets.

For example :

Order number | date worked | note


Is it feasible to import their data to a central worksheet?

I'd eventually like to pull and push data to this central worksheet. Will I run into massive slowdown from accessing the worksheet frequently to pull and push this data?

Lockback
Sep 3, 2006

All days are nights to see till I see thee; and nights bright days when dreams do show me thee.
I think this is a stupid question but I can't figure this out. I have a list of data that I need to convert to a Dimension & Measurement format. Right now it looks like:
code:

Time        App1_consumer        App2_consumer       App3_consumer
12:00           3                       5                6
12:05           3                       6                6
12:10           4                       5                2
12:15           3                       9                6

I need it to look like this

code:

Time        Application      Consumer Count        
12:00           App1                3                    
12:00           App2                5
12:00           App3                6
12:05           App1                3                    
12:05           App2                6
12:05           App3                6   
12:10           App1                4                    
12:10           App2                5
12:10           App3                2                                        

I tried a Pivot table but either I can't get it in that format or I was just unaware on how to do it. Ideas?

Edit: need to unpivot from power query, I think I got it.

Lockback fucked around with this message at 19:17 on Feb 19, 2019

nielsm
Jun 1, 2009



Is there a good way to make a "best fit" lookup in a table?

Scenario: I have a collection of network latency measurements from a large number of computers across multiple days, and several measurements each day. In another table, I have collected the active network interfaces around the time of each latency measurement. I want to select the most likely network interface used for the measurement for each measurement, based on same date, proximity in time, and network interface with the lowest routing metric value.

Is this a job for VBA?

nielsm
Jun 1, 2009



I think I almost found a solution. If I make a composite key column I can (almost) use VLOOKUP with the range_lookup True. The only issue is that I want the first value greater than the key, rather that the last value smaller than the key. Maybe I can do some trickery with inverting one or more of the parts of the key.

Wandering Orange
Sep 8, 2012

Switch to INDEX(MATCH()) instead of VLOOKUP. The last argument of MATCH() is a -1,0,1 value that specifies how the lookup value is compared in the lookup array; a value of -1 will find the smallest value that is greater than or equal to the lookup.

double nine
Aug 8, 2013

Is there a good way to make a formula go through a row and for each not-blank cell, return the content of the first row?

Basically, I'm building an overview of my books, and I'm thinking of a system where for a specific book, I put 1s in the correct categories - say fiction, historical, crime - and have one cell that lists the header for each cell with 1s in it.

I'm partially there through the following:

if(isblank(B13),"", $B$1&", ")

Will return the column title for B. But doing it this way for all columns would take a lot of imputing each column, I'd like to avoid this.

Essentially I want to get to this - with C2 in this case being the programmed content and the rest manual inputs :

code:
   A		B		C					D
1						  			sci-fi	   horror	 politics	  detective	ecology		
2 Frank Herbert	Dune		Sci-fi, politics, ecology		1			1				1
3 Dougl. Adams	Dirk Gently	Sci-fi, detective			1				  	  1

double nine fucked around with this message at 23:31 on Mar 23, 2019

Ninja.Bob
Mar 31, 2005
Here is a function:
code:
Option Explicit

Public Function ConcatHeaders(headerRow As range, cellRow As range) As String
    Dim i As Integer
    For i = 1 To cellRow.Cells.Count
        If cellRow.Cells(i).Value <> "" Then
            ConcatHeaders = ConcatHeaders + headerRow.Cells(i).Value + ", "
        End If
    Next
    ConcatHeaders = Left(ConcatHeaders, Len(ConcatHeaders) - 2)
End Function
In the vba editor (Alt + F11) create a module (Insert > Module) and paste it in. You can then use it in your workbook like =ConcatHeaders($D$1:$H$1,D2:H2) and copy it down.

double nine
Aug 8, 2013

thanks. I added an iferror to make it less ugly at the start but it looks exactly like I need to.

one of these days I'm gonna learn vb, I swear.

Nazattack
Oct 21, 2008
Someone else used to do this, they did it manually each time for some reason.

https://imgur.com/a/onFO0Ps

How can I reference the cell value as part of the formula to reference another sheet's data? The "t" in the picture can ideally be set by the cell above "Sales Person"'





I decided to take one last stab at it, and I got it working. Figured I'll still post. Maybe this can help someone else out.

=indirect("'2019Mirror'!$"&T$2&row())

Sad Panda
Sep 22, 2004

I'm a Sad Panda.
A student gets a level 9, their below target is 1-4, good is 5-6 and excellent is 7-9. The spreadsheet should see this and say "Excellent". I've come up with 2 solutions for this so far.

Solution 1. I managed to solve this using 3 bonus columns that just use LEFT() to get the 1/5/7 from those target ranges and then an INDEX(MATCH()) to look it up. See attached pic.

Solution 2. I took an average of the good column (so 5.5 in the above example). I then created a table combined with a Vlookup to see if they were above/on/below target.

Is there a better way that doesn't involve creating those extra columns? I asked some people and they just keep saying "Use a VLookup" but don't explain it. I'm pretty sure that Excel doesn't know that 1-4 means the numbers 1, 2, 3, 4 inclusive which would mean that a VLookup without my bonus columns from the attached picture wouldn't work.

Only registered members can see post attachments!

esquilax
Jan 3, 2003

Sad Panda posted:

A student gets a level 9, their below target is 1-4, good is 5-6 and excellent is 7-9. The spreadsheet should see this and say "Excellent". I've come up with 2 solutions for this so far.

Solution 1. I managed to solve this using 3 bonus columns that just use LEFT() to get the 1/5/7 from those target ranges and then an INDEX(MATCH()) to look it up. See attached pic.

Solution 2. I took an average of the good column (so 5.5 in the above example). I then created a table combined with a Vlookup to see if they were above/on/below target.

Is there a better way that doesn't involve creating those extra columns? I asked some people and they just keep saying "Use a VLookup" but don't explain it. I'm pretty sure that Excel doesn't know that 1-4 means the numbers 1, 2, 3, 4 inclusive which would mean that a VLookup without my bonus columns from the attached picture wouldn't work.



If you use a vlookup with "true" instead of "false" then it will match the highest value that doesn't exceed your lookup number. So a table like:

0 Below Target
5 Good
7 Excellent

A vlookup will take a numeric score like 5.25, and will look it up on the table to output the words.



You could also do this via an index(match()) with a match type of 1, sort of like how you did. But generally just having a table in a hidden column off to the right is the best move here.

esquilax fucked around with this message at 18:58 on Apr 7, 2019

Richard Noggin
Jun 6, 2005
Redneck By Default
There's a third way, although it's (arguably) not as clean as using a lookup table.

Only registered members can see post attachments!

Busy Bee
Jul 13, 2004
I have the latest version of Excel and whenever I do a Find and Replace -> Replace All -> Dialog pops up saying they made XX,XXX replacements and I click okay -> My Excel hangs and freezes for at least a minute and I can't do anything. What's going on here and how can I fix this?

Adbot
ADBOT LOVES YOU

fosborb
Dec 15, 2006



Chronic Good Poster
you have a bunch of volatile equations that are all recalculating on every replacement. If it is that much of a big deal, go to formulas, calculation options, set to manual until you're done with your find/replace.

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