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
Karia
Mar 27, 2013

Self-portrait, Snake on a Plane
Oil painting, c. 1482-1484
Leonardo DaVinci (1452-1591)

CellBlock posted:

Maybe this is a bigger question and only tangentially related to Excel, but here goes:

End users will be filling out forms that are created as Excel files. I'll have some control over these forms, but not a lot. Users will then upload those forms through our website. What I'm hoping to be able to do is validate those files against a "master" copy. I can't just hash the files, because users will be inputting data, but I want to be able to check that users haven't altered the framework/layout/general structure of the file so I can trust that I can find the data they've entered.

I know we can protect ranges on the forms to try to prevent those edits; is there a way to detect those edits afterward? (It's cool if it requires something like a Java library.)

Well, first, you can specifically lock the formatting and such and only allow users to fill in specific cells.
https://support.microsoft.com/en-us/office/protect-a-worksheet-3179efdb-1285-4d49-a9c3-f4ca36276de6

Basically, you set all the cells you want the user to be able to type stuff into to unlocked. Then in the Review tab, turn on both Protect Sheet for all relevant sheets (and uncheck 'Select locked cells', that way users can't even select anything they're not supposed to) and Protect Workbook with whatever passwords you want.


Alternatively, have you considered not using Excel for this? Getting a web form set up to collect the data and put it straight into your database seems like a better idea.

Adbot
ADBOT LOVES YOU

CellBlock
Oct 6, 2005

It just don't stop.



Karia posted:

Alternatively, have you considered not using Excel for this? Getting a web form set up to collect the data and put it straight into your database seems like a better idea.

We don't own the files; it's a government entity using them to make digital versions of a paper form to submit for processing. (Currently, they can submit pretty much whatever, and they usually use different spreadsheet formats; the government is just trying to standardize the format so we can read them.)

Ideally, we'd probably just use some sort of XML or another data format, but then the users would need software to produce that data format, and everyone already has Excel.

TheLastManStanding
Jan 14, 2008
Mash Buttons!
If you don't mind programming, then look into editing files through the component object model. You could write a script that could take an excel file, pull out the user inputted cells, insert them into your blank template, then save it out as a validated file. For tasks like this I prefer AutoHotkey, but it could be done in any language .

DRINK ME
Jul 31, 2006
i cant fix avs like this because idk the bbcode - HTML IS BS MAN
.xlsx is really .zip containing .xml. If you wanted to you could pull out the xml for your sheet and compare known tags I guess. Like you know your template has “<A1>Title</A1>” and compare that to the completed form, repeat for however many you want to check. I’m not smart on how best to do that.

In Excel I’ve done something similar in the past that seemed to work. I copied my template to another sheet and then on a third sheet used =Template!A1=Hidden_Template_Copy!A1, copied that formula for all the cells I wanted to make sure were the same, and then at the bottom of the sheet I did =AND(A1:Z1000). If any of the expected values had changed that cell would show as FALSE. Then in I set those two sheets it xlveryhidden so the casual observer will never see them.

mystes
May 31, 2006

DRINK ME posted:

.xlsx is really .zip containing .xml. If you wanted to you could pull out the xml for your sheet and compare known tags I guess. Like you know your template has “<A1>Title</A1>” and compare that to the completed form, repeat for however many you want to check. I’m not smart on how best to do that.
Just comparing the tags against the original file definitely isn't going to work because of how complicated the format is. You need an actual xlsx parsing library but as long as you just need to do some basic sanity check on the values of the cells (and not worry about the formatting, etc.) before you pull the data out it should be doable.

mystes fucked around with this message at 16:48 on Jul 4, 2020

Mr Crucial
Oct 28, 2005
What's new pussycat?
I have a massive Excel spreadsheet that I need to normalise. The sheet has 26 columns containing information about users, groups and computers. The typical sheet will have tens of thousands of rows at minimum, potentially up to a few million. A very basic example:

code:
Machine		User	Groups			OS		User Description
computer1	JeffK	admins; users; blah 	Windows 10	Administrator for X
computer1	BobS	users; blah		Windows 10	User in Y dept
server2		JeffK	admins; remote;		Windows 2016	Administrator for X
computer2	BobS	users; blah		Windows 7	User in Y dept
server3		root	root			Solaris 11	root account
(Plus a bunch of other columns which are generally related to one of the three object types.)

Ultimately what I'd like to do is get all this data into some sort of database that is normalised, that is with individual user, group and machine tables each linked by pivot tables. The ultimate goal is to then have the ability to query this database and run analytics, as well as 'browse' the data by quickly looking at, for example, which users are in particular groups, which users have access to particular machines, etc.

Can anyone recommend some sort of tool which can help do this?

I've tried using PowerShell but this fails completely at large scale. I looked at PowerBI as well but it assumes that the data you want to look at is either already normalised or at least much simpler than what's in my data.

nielsm
Jun 1, 2009



Put that poo poo in a real database. Even SQLite or Access will be better than Excel.

Mr Crucial
Oct 28, 2005
What's new pussycat?

nielsm posted:

Put that poo poo in a real database. Even SQLite or Access will be better than Excel.

That's what I'm trying to do. However, I'm stuck with the source data as this giant unwieldy Excel spreadsheet and I can't figure out a good way of doing the conversion.

Karia
Mar 27, 2013

Self-portrait, Snake on a Plane
Oil painting, c. 1482-1484
Leonardo DaVinci (1452-1591)

Access has tools for importing excel files. You could also export as a csv, that might be easier to import into some databases.

nielsm
Jun 1, 2009



Initially load the data into Access as-is, then write some queries or VBA to normalize it. Maybe there's also built in tools to turn columns with lists like your groups column into normal form, I never really looked.

Drimble Wedge
Mar 10, 2008

Self-contained

I am trying to make a pivot table which will give the *total* times for each person:

Gene 0:11:45
Alex 0:09:14
Mona 0:08:19
Bev 0:08:06
Bev 0:07:48
Fred 0:07:37
Andy 0:07:30
Chris 0:07:27
Sami 0:07:23
Shirley 0:07:08
Fred 0:07:05
Gene 0:06:56
Gene 0:06:52
Naomi 0:06:44
Bev 0:06:25

so that the output shows Bev 22:19 and so on. I know this should be super obvious and easy but I can't seem to hit on the right formula or search term.

nielsm
Jun 1, 2009



Just add the name column as a row field and the time column as a value field in the pivot table. It sums the values per name by default then.

Assuming the times are represented as normal time values, that is. If they are text values you'll need to parse them first, do that before making the pivot.

Drimble Wedge
Mar 10, 2008

Self-contained

You are a thing of beauty and a joy forever; that worked perfectly! Thank you.

Everett False
Sep 28, 2006

Mopsy, I'm starting to question your medical credentials.

Is there an easy way in VBA to set the value of a cell to the value of VLOOKUP([@column], [table in another workbook], #, FALSE)? I'm looping through a list of tables and want to get rates from a summary table in a completely different workbook without having to do more loops to find the right row. I guess in theory I could just put in the VLOOKUP function I need and then copy/paste as values, but that seems... inelegant.

mystes
May 31, 2006

KentuckyFriedBonBon posted:

Is there an easy way in VBA to set the value of a cell to the value of VLOOKUP([@column], [table in another workbook], #, FALSE)? I'm looping through a list of tables and want to get rates from a summary table in a completely different workbook without having to do more loops to find the right row. I guess in theory I could just put in the VLOOKUP function I need and then copy/paste as values, but that seems... inelegant.
If you want to use vlookup why don't you just set the cell to that formula? Otherwise maybe you could use evaluate or something and set the cell to the result or something if you really wanted to.

DRINK ME
Jul 31, 2006
i cant fix avs like this because idk the bbcode - HTML IS BS MAN
You can use Worksheetfunction.Vlookup in your VBA.
Something like this (not in front of Excel so may need correcting):
My_lookup_value = worksheetfunction.vlookup(A2,Sheet2!A1:B3,2,0)
Range(“A1”) = My_lookup_value

The formatting of the formulas in VBA can be a bit weird, I don’t think you need to R1C1 format but maybe add your formula in the cell and then record it as a macro to use in your code. Saves time dicking about with getting the quotes in the right places and whatnot.

And yeah, the inelegant solution works fine to:
A1 = vlookup
A1.copy
A1.pastespecial as value

—-
edit:
Half an hour later a little voice in my brain told me I was stupid, this would be much simpler:

Range(“A1”) = worksheetfunction.vlookup(A2,Sheet2!A1:B3,2,0)

DRINK ME fucked around with this message at 05:32 on Jul 17, 2020

mystes
May 31, 2006

Microsoft has apparently added support to Power Automate that allows it to run Excel javascript scripts outside of an interactive Excel session (previously they would just run in desktop Excel or your own browser in the online version).

I don't think anyone will actually use this because nobody uses power automate and right now it sounds like this has to be specifically enabled, but if it works this could potentially be MUCH more reliable than using VBA or COM with desktop Excel.

raej
Sep 25, 2003

"Being drunk is the worst feeling of all. Except for all those other feelings."
I'm trying to create a dropdown list for cells based on a column. Normally, this isn't a big deal, you go to Data Validation, allow list, select range, and BAM, everything works.

I'm not sure what I'm missing, but when I check the "Ignore Blank" box, it still includes blanks in my list:

Created Data Validation dropdown:


Data Validation Settings:


Data table pulling from:

mystes
May 31, 2006

raej posted:

I'm trying to create a dropdown list for cells based on a column. Normally, this isn't a big deal, you go to Data Validation, allow list, select range, and BAM, everything works.

I'm not sure what I'm missing, but when I check the "Ignore Blank" box, it still includes blanks in my list:

Created Data Validation dropdown:


Data Validation Settings:


Data table pulling from:

I think maybe "Ignore Blank" refers to the cell you're validating, not the range you're using as the source, so you probably have to do something more complicated.

Harminoff
Oct 24, 2005

👽
Yeah looks to be way more complex than it should be. Found this


https://www.youtube.com/watch?v=6PcF04bTSOM

raej
Sep 25, 2003

"Being drunk is the worst feeling of all. Except for all those other feelings."

Harminoff posted:

Yeah looks to be way more complex than it should be. Found this


https://www.youtube.com/watch?v=6PcF04bTSOM

Holy wow. Great find there. This should do the trick in my overly complicated spreadsheet of dynamicness. Thanks!

Everett False
Sep 28, 2006

Mopsy, I'm starting to question your medical credentials.

At some point one of my pivot tables seems to have turned into a power pivot table, which means now all my GETPIVOTDATA functions that used that table are borked. :1 Basically I had a cell that looked like this:
code:
=GETPIVOTDATA("Reg Hours",Pivot!A3,"EMP #",B5,"FUND",101,"ACCOUNT #",D5)
But now for it to actually show the number I want it has to look like this:

code:
=GETPIVOTDATA("[Measures].[Sum of REG]",Pivot!$A$3,"[Board].[EMP #]","[Board].[EMP #].&[0000000]","[Board].[FUND]","[Board].[FUND].&[000]","[Board].[ACCOUNT #]","[Board].[ACCOUNT #].&[000000000]")
Should I just regenerate the pivot table and give it the same name so I don't have to redo my functions, or is keeping it a power pivot table better for some reason?

Also I forgot to post and say so but application.vlookup totally worked in solving my previous problem. :3:

Papa Was A Video Toaster
Jan 9, 2011





How do I make an array of sliders always sum to 100%? Something kinda like how Humble Bundle lets you distribute your donation. I'm looking to forecast profits with different sales distributions. So far I have a SUMPRODUCT of my different SKUs profitability as a percentage and some arbitrary weights. I just want to be able to futz about with the weighting and have it sanity check me that it adds to 100% when I hit submit or something.

Papa Was A Video Toaster
Jan 9, 2011





Just gonna keep asking questions and maybe one day they'll be answered.
How do I like "future proof" my summary/aggregate sheet?
Right now I have the first sheet in the book that is pricing and aggregate sales and the next sheet is sales for August. How do I make a formula that calls August sales and each subsequent month and sums them without having to rewrite my formula for the front page every time?

nielsm
Jun 1, 2009



Uh probably something with INDIRECT and matrix formulas, I'm not sure if there is a good way to detect what sheet names exist. You may need to at the very least maintain a table of the sheet names/other identities to use.

Papa Was A Video Toaster
Jan 9, 2011





nielsm posted:

Uh probably something with INDIRECT and matrix formulas, I'm not sure if there is a good way to detect what sheet names exist. You may need to at the very least maintain a table of the sheet names/other identities to use.

I've decided that I'm just going to bound it to the calendar year for this book and then I'll figure out how to call between books for a multiyear aggregate book later on.

I have a table of sheet references for the rest of the months of the year now, but the way my INDIRECT is written it doesn't increment down the column when I drag like I want it to.
code:
=SUM(INDIRECT("'"&$S$15&"'!N2"),INDIRECT("'"&$S$16&"'!N2"))
So I think that calls the sheet names from S15 and S16 absolute and the address N2 on that sheet. I want to add the next 3 months, then control+drag that formula down so the next one is N3, etc. I probably have too many quotes or something, I just copied an example.

Edit: I tried using a CELL function because that's what I found on Google and it doesn't work. Points at the sheet it is on rather than the one I'm trying to point the indirect at.
code:
=SUM(INDIRECT($S$15&"!"&CELL("address",N2)),INDIRECT($S$16&"!"&CELL("address",N2)))

Papa Was A Video Toaster fucked around with this message at 16:37 on Aug 13, 2020

mastersord
Feb 15, 2001

Gold Card Putty Fan Club
Member Since 2017!
Soiled Meat
I looked up how INDIRECT works so i could try and understand what you're trying to do and how. It looks like it needs to use a worksheet name that it references from another cell
https://www.excel-easy.com/examples/indirect.html
https://www.contextures.com/xlFunctions05.html

I did find a way to use a formula to generate a list of worksheet names at HowtoExcel.org:

quote:

1. Go to the Formulas tab.
2. Press the Define Name button.
3. Enter SheetNames into the name field.
4. Enter the following formula into the Refers to field:
code:
=REPLACE(GET.WORKBOOK(1),1,FIND("]",GET.WORKBOOK(1)),"")
5. Hit the OK button.
6. In a sheet within the workbook enter the numbers 1,2,3,etc… into column A starting at row 2 and then in cell B2 enter the following formula and copy and paste it down the column until you have a list of all your sheet names:
code:
=INDEX(SheetNames,A2)

Now you need a count of how many worksheets are in the book, or assume a max amount and add some functionality to hide index values that don't exist.

Papa Was A Video Toaster
Jan 9, 2011





So it turns out I was kinda right with the quotes thing.
code:
=SUM(INDIRECT($S$15&"!"&CELL("address",N2)),INDIRECT($S$16&"!"&CELL("address",N2)))
This code doesn't escape spaces in the sheet name. I switched the sheet name to use underscores and it works.

Papa Was A Video Toaster
Jan 9, 2011





How do I save a selection? I have a bunch of dummy data I copied across my sheets to do the testing that I now want to clear. It's all in exactly the same areas.
Also how do add a new row across multiple sheets?

Edit: both questions had the same answer. Select multiple sheets with Shift.

Papa Was A Video Toaster fucked around with this message at 17:43 on Aug 13, 2020

hummingbird hoedown
Sep 23, 2004


IS THAT A STUPID NEWBIE AVATAR? FUCK NO, YOU'RE GETTING A PENTAR

SKILCRAFT KREW Reppin' Quality Blind Made Products
I have an IF statement that should be pretty straightforward but doesn't seem to be working for the value_if_false part.

=IF(MATCH(serial number, column of serial numbers to check against, 0), "Match", "No Match")

The "Match" works but if I enter a non matching serial number, or anything other than a number from the column of numbers being looked up, the cell remains at #N/A.

What might be going wrong here?

Whybird
Aug 2, 2009

Phaiston have long avoided the tightly competetive defence sector, but the IRDA Act 2052 has given us the freedom we need to bring out something really special.

https://team-robostar.itch.io/robostar


Nap Ghost

hummingbird hoedown posted:

I have an IF statement that should be pretty straightforward but doesn't seem to be working for the value_if_false part.

=IF(MATCH(serial number, column of serial numbers to check against, 0), "Match", "No Match")

The "Match" works but if I enter a non matching serial number, or anything other than a number from the column of numbers being looked up, the cell remains at #N/A.

What might be going wrong here?

If MATCH can't find a match, it returns #N/A. You either want to use COUNTIF(column, serial number)>0 or wrap the MATCH in an ISNA instead.

tuyop
Sep 15, 2006

Every second that we're not growing BASIL is a second wasted

Fun Shoe

hummingbird hoedown posted:

I have an IF statement that should be pretty straightforward but doesn't seem to be working for the value_if_false part.

=IF(MATCH(serial number, column of serial numbers to check against, 0), "Match", "No Match")

The "Match" works but if I enter a non matching serial number, or anything other than a number from the column of numbers being looked up, the cell remains at #N/A.

What might be going wrong here?

IF can only work if the first argument evaluates to TRUE or FALSE (or [any number but 0] or 0, same thing). Using ISNA will let you make MATCH do that. I would just make the NA condition of ISNA return 0.

hummingbird hoedown
Sep 23, 2004


IS THAT A STUPID NEWBIE AVATAR? FUCK NO, YOU'RE GETTING A PENTAR

SKILCRAFT KREW Reppin' Quality Blind Made Products
The above advice worked. Thank you!

The last piece to this project I can't do on my own deals with switching cells. I want to be able to scan a barcode (column a) then tab over to column b to scan a status from a reference sheet of barcodes. Then I'd like the active cell to jump back to column a of the row under the active row. I can program the barcode scanner to send the tab key after a decode, so going from column a to b is not a problem. I don't know how to write a macro that would send the active cell to column a on the row under the active row after a tab character.

DRINK ME
Jul 31, 2006
i cant fix avs like this because idk the bbcode - HTML IS BS MAN
If I’m reading that correctly: when a value is entered in column B, move to the next row on column A?

You could do something like this in the worksheet code
code:
Private sub worksheet_change(byVal target as range)

If Target.cells.Count > 1 or Isempty(Target) then exit sub

If target.column = 2 then
   Application.Enableevents = false
   Target.offset(1, -1).Select
   Application.Enableevents = true
End if

End sub
The first line checks to make sure it’s not a multiple selection (like a user selecting data) or is not empty (a user deleting data).

The next line checks we’re in column B (column 2). If we are then the current cell is offset by 1 row and -1 columns (the next row in column A).

DRINK ME fucked around with this message at 23:04 on Aug 30, 2020

hummingbird hoedown
Sep 23, 2004


IS THAT A STUPID NEWBIE AVATAR? FUCK NO, YOU'RE GETTING A PENTAR

SKILCRAFT KREW Reppin' Quality Blind Made Products

DRINK ME posted:

If I’m reading that correctly: when a value is entered in column B, move to the next row on column A?

You could do something like this in the worksheet code
code:
Private sub worksheet_change(byVal target as range)

If Target.cells.Count > 1 or Isempty(Target) then exit sub

If target.column = 2 then
   Application.Enableevents = false
   Target.offset(1, -1).Select
   Application.Enableevents = true
End if

End sub
The first line checks to make sure it’s not a multiple selection (like a user selecting data) or is not empty (a user deleting data).

The next line checks we’re in column B (column 2). If we are then the current cell is offset by 1 row and -1 columns (the next row in column A).

Thanks for the help. I just got around to trying this out but nothing happened. When column B is active, I populate a cell in it, then do anything else, the selected cell behaves as it normally does(Enter moves the active cell on row down, Tab moves the active cell one column to the right, etc.)

Hughmoris
Apr 21, 2007
Let's go to the abyss!
This is tangentially related to Excel and the O365 ecosytstem, not sure of a better thread to put this in.

Has anyone used Microsoft Flow / Power Automate? I just discovered it, and am currently a solution looking for a problem. I'm looking at my daily/weekly tasks and seeing how I can use it to automate some Excel -> Outlook -> OneNote flows.

mystes
May 31, 2006

Hughmoris posted:

This is tangentially related to Excel and the O365 ecosytstem, not sure of a better thread to put this in.

Has anyone used Microsoft Flow / Power Automate? I just discovered it, and am currently a solution looking for a problem. I'm looking at my daily/weekly tasks and seeing how I can use it to automate some Excel -> Outlook -> OneNote flows.
I've used it, but it doesn't seem to be very popular and the pricing model is dumb. Also, sometimes it just won't have the trigger or action you want and then there's nothing you can do about it.

The beta functionality to run Excel scripts seems like it could be interesting but it only works in the business version and it needs to be specifically enabled.

In general I'd prefer to use something else if possible, but it's probably one of the easiest ways to interact with outlook/o356 and if it works I'd much rather try to use the excel script functionality than vba/com for anything automated.

mystes fucked around with this message at 19:34 on Sep 13, 2020

Harminoff
Oct 24, 2005

👽
It also only works with excel online files, mostly with just tables too if I remember correctly.

I have to do some dumb poo poo like have excel scrape data from multiple workbooks using vba, compile it and send a report using vba yo email, then upload some stats to SharePoint using vba so that I can create power bi dashboards using that data. Pretty crazy and I'm sure there is a better way to do it. Hopefully office script can help with some of it.

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

hummingbird hoedown posted:

Thanks for the help. I just got around to trying this out but nothing happened. When column B is active, I populate a cell in it, then do anything else, the selected cell behaves as it normally does(Enter moves the active cell on row down, Tab moves the active cell one column to the right, etc.)

Weird stuff. Check you have macro/code enabled. Check you have added it to the worksheet you are using - this needs to be against the sheet, if you look at the project browser in the code view / vba there will be Microsoft Excel Objects and your list of sheets. Pick the sheet you are using and add it there.

A good way to check if it is firing or not would be to add something visual to the code. Like in the first line add msgbox “code fired” and then go change a value in column B. If it’s working it should give you a message box pop up.

Adbot
ADBOT LOVES YOU

disaster pastor
May 1, 2007


I'm currently using a very basic formula for weighted averages: (B2*0.1)+(C2*0.1)+(D2*0.1)+(E2*0.2)+(F2*0.25)+(J2*0.25)

This is for predictions, and I'd like to run a Monte Carlo experiment on it: do it, say, 5000 times with different weights. The trouble is I can't figure out how to constrain the weights. At the very least, I'd need them all to sum to 1, and I can't do that by just multiplying by RAND(). I could approximate it by doing RANDBETWEEN() (and dividing by 100) but that could still be quite a bit off in either direction.

I searched online and most of the solutions I found were to make five of them random and the sixth 1 minus the sum of the other multipliers, which won't work for me; not only am I not sure offhand how to write that formula so that it works 5000 times, but also, if I'm doing this 5000 times, many of those 1-SUMs will end up negative.

Is the RANDBETWEEN method my best option, or is there a smarter way to do this?

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