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
kapalama
Aug 15, 2007

:siren:EVERYTHING I SAY ABOUT JAPAN OR LIVING IN JAPAN IS COMPLETELY WRONG, BUT YOU BETTER BELIEVE I'LL :spergin: ABOUT IT.:siren:

PLEASE ADD ME TO YOUR IGNORE LIST.

IF YOU SEE ME POST IN A JAPAN THREAD, PLEASE PM A MODERATOR SO THAT I CAN BE BANNED.
Excel formatting question:

This is an order sheet.

I want to keep a running total that is only displayed when the total actually increases from a line total. Not really used to doing this, but I got it to work OK as long as I have two dummy rows to start things, but of course it sums the column, instead of updating the the value. How do I get this to work so that every time a row causes an increase in the running order total it adds to the running total and displays the updated total? Obviously I could have zero appear in a bunch of rows but it makes reading the order sheet hard

=IF((F4>0),(F4+SUM(G$2:G3)),"") first guess gets the blanks right, but of course just sums all the displayed values.

This might be easy, but I have never really needed to do this before.

Adbot
ADBOT LOVES YOU

esquilax
Jan 3, 2003

kapalama posted:

Excel formatting question:

This is an order sheet.

I want to keep a running total that is only displayed when the total actually increases from a line total. Not really used to doing this, but I got it to work OK as long as I have two dummy rows to start things, but of course it sums the column, instead of updating the the value. How do I get this to work so that every time a row causes an increase in the running order total it adds to the running total and displays the updated total? Obviously I could have zero appear in a bunch of rows but it makes reading the order sheet hard

=IF((F4>0),(F4+SUM(G$2:G3)),"") first guess gets the blanks right, but of course just sums all the displayed values.

This might be easy, but I have never really needed to do this before.

Do you have any issues using conditional formatting? You can have the formula in your cells equal the running total in each row, then set the font of the text to white when it's the same as the row above it in order to make it invisible.

invision
Mar 2, 2009

I DIDN'T GET ENOUGH RAPE LAST TIME, MAY I HAVE SOME MORE?
My job relies *extremely heavily* on excel, and because of that our "command and control" is all done in an excel book. A lot of it is just sorting information and launching applications and internal sites/tools from it, but there's definitely some insanity happening when you hit alt+f11.

Problem:
A lot of our equipment that we rely on this sheet to be able to use in anything close to "in a timely manner" is being replaced/renewed/added on to. This has created a whole bunch of smaller problems like incorrect or missing data that we then have to go digging around to find. Another issue is that we have a LOT of contract crews working on our equipment right now, and it's becoming a pretty big issue because they aren't checking in/out with us, or they'll leave equipment in alarm or offline and no one has any record of them ever being on site.

Solution:
Whipped up a quick SQLite db with a really simple front-end in python using flask on one of my servers. This is nice, but it's a pain in the rear end to have to constantly refresh and search through it to see what's going on where. Then I discovered the web browser object in excel. Now whenever someone pulls up a site to check on it from the spreadsheet, they also get a small web-browser box on the same sheet that requests a internalsite.com/sitenotes/<siteid> url, then displays the notes for the site in chronological order, with a small "add info" submission form at the bottom. It also has the ability to float information at the very top of the web browser object, like new IP's, equipment ID's, etc. Since all of the lifting is done on my server, we can have multiple people doing things with the same site at one time, and have new notes appear to everyone else in real-time, which has made it WAY better.
The sheet has an input box in A2 that does all kinds of wizardy vlookup stuff to fill out the rest of the sheet - you can put in site id, site name, ip address, and like 10 other things, even partially, and it'll fill the rest of the sheet. Multiple matches? You get a dropdown list to choose from.

Questions:

Is there a way to test the connection to the server, and if it's not available have it disable all web-based stuff?

Now that I have the web-browser built-in, I'd like to be able to do something like "If notes show a new IP address that you don't have in your workbook, add or replace it in the appropriate table". If I could do it straight out of the web browser object somehow, that'd be rad, but I'm assuming that I'll have to trigger a web data connection and pull the data in, then replace it. Is there a way to have the web data connection only import certain tags? Would it be possible to have the webpage display an IP surrounded by <siteid_ipaddress> tags, and then have it pull only that tag? Is it possible to grab the HTML from the browser object within excel using VBA? This would be helpful for a couple of other things I'd like to do.


Sometimes when a note is added, it also needs to be emailed to a pre-determined group of people, and also added to another site. Is it possible to have the sheet send an email from outlook? I.E. if steve adds a note that needs to be emailed also, it would add the note and submit the form, then shoot off an email from his outlook to a hardcoded email address? What would be the most seamless way to do that?

Are there 'native' Telnet/SSH objects? Specifically ones that I can scrape? Being able to spawn an invisible telnet session that runs a command or two in the background, parses it, then puts the result in a cell somewhere would be amazing.


We obviously broke the scope of excel a longgggggggggggggggg time ago. I loathe VBA and really don't like excel that much either, but we deal with a tonnnnnnnnnnnn of data and my coworkers are all old and just set in using excel/vba, especially since we run into all kinds of edge cases that need something in it done a little differently, and it's quicker for them to just smash some VBA out inside of the workbook than it is to deal with ssh'ing into a server and coming up with a solution that doesn't break everything for everyone else. We also have a lot of techs that might not have internet but still need the spreadsheet to be able to work, so having everything locally and portable is pretty important. It's a pain in the rear end.

invision fucked around with this message at 07:21 on Sep 24, 2015

fosborb
Dec 15, 2006



Chronic Good Poster
Holy poo poo.

invision
Mar 2, 2009

I DIDN'T GET ENOUGH RAPE LAST TIME, MAY I HAVE SOME MORE?
e:nvm

invision fucked around with this message at 07:20 on Sep 24, 2015

DRINK ME
Jul 31, 2006
i cant fix avs like this because idk the bbcode - HTML IS BS MAN
And I thought I'd seen overuse of Excel before. That is something else...

It's totally possible to send Outlook emails from Excel, you can even choose to send without prompt or simply pop the filled out email for the user to complete, review and send and there's some handy url validity checking code out there. Phone posting so don't have either at hand. Beyond that you're way out of my scope of somewhat-overusing-Excel.

fosborb
Dec 15, 2006



Chronic Good Poster
There is an http object model that can interact directly with the DOM. You should be able to use that, or at least scrape the results with a regex (another include)

Outlook has an object model, as do all Office apps. There may be some increased security around it depending on your Office version. But it's easy to use.

Telnet, no idea. In sure something out there exists, but I doubt it's native. Might want to see what you can script, log, and scrape from something like PuTTY.

If you're looking for a path away from excel, I'd suggest vbscript. Cscript.exe will be on every machine, the only real difference is late binding everything, and you won't need a folder of macrobooks to run your company's back end.

fosborb
Dec 15, 2006



Chronic Good Poster
I'm wrong. You can use MSWinsockLib.Winsock and the SendData and GetData methods to run and read telnet sessions from Excel.

May God have mercy on your soul.

kapalama
Aug 15, 2007

:siren:EVERYTHING I SAY ABOUT JAPAN OR LIVING IN JAPAN IS COMPLETELY WRONG, BUT YOU BETTER BELIEVE I'LL :spergin: ABOUT IT.:siren:

PLEASE ADD ME TO YOUR IGNORE LIST.

IF YOU SEE ME POST IN A JAPAN THREAD, PLEASE PM A MODERATOR SO THAT I CAN BE BANNED.

kapalama posted:

Excel formatting question:

This is an order sheet.

I want to keep a running total that is only displayed when the total actually increases from a line total. Not really used to doing this, but I got it to work OK as long as I have two dummy rows to start things, but of course it sums the column, instead of updating the the value. How do I get this to work so that every time a row causes an increase in the running order total it adds to the running total and displays the updated total? Obviously I could have zero appear in a bunch of rows but it makes reading the order sheet hard

=IF((F4>0),(F4+SUM(G$2:G3)),"") first guess gets the blanks right, but of course just sums all the displayed values.

This might be easy, but I have never really needed to do this before.

esquilax posted:

Do you have any issues using conditional formatting? You can have the formula in your cells equal the running total in each row, then set the font of the text to white when it's the same as the row above it in order to make it invisible.

Quoting myself in case anyone else needs to do this.

Making the text white was not a solution because instead of a running total , it would just keep summing all entries including repeated running total entries.

What I did was just keep a running total in one column, which of course results in many repeats of an unchanged running total, and then added another column with the logic

=IF((G2=G3),"",G3) (all relative values)

Which blanks the display of the previous columns running total when it is a repeat of the value above, and and displays it the running total if it is a new value.

And then I hid the running original running total column.

SO now I have a overly busy many repeating values running total column (that I hide) and a new column which only displays a value when the running total is updated, which is what I wanted. I just forgot to use the hidden columns to get things done.

Reik
Mar 8, 2004
Posted this in the general programming question thread not realizing there was one specific for Excel, sorry if you end up reading both posts.

I am not a programmer, I am an actuary, but I have a project I'm working on that involves automation of testing on a government website. The process we have in place from last year involved just running the site through Internet Explorer using VBA to fill out forms, push button, and pull text dumps from the pages in question. Unfortunately this year they updated the website and it appears our version of Internet Explorer, IE8, no longer works with this website. We do have access to Chrome thank god, but the VBA code we use only works in IE. I've looked up solutions to this problem and it looks like there are multiple simple solutions out there, but I'm trying to find one that meets the following restrictions:

1. Can't upgrade IE version.
2. Can't install any new software or plugins as these require approval from IT.

Is there any possible way to automate testing using VBA with Google Chrome? I know this isn't a hard problem, I just have some serious limitations due to Corporate America. I've recommended we request access for Firefox, the Selenium IDE plugin for Firefox, and the Selenium VBA plugin for Excel as a solution to this project, but I don't know if and when that can get approved.

Are there any solutions to this problem within my limitations? Is there some way to trick VBA in to thinking Chrome is actually Internet Explorer so that I can use the built-in objects and code stuff to automate Chrome?

ShimaTetsuo
Sep 9, 2001

Maximus Quietus
How exactly were you doing this before? Using the IE COM library? Have you tried using the WinHTTP library instead? It should come with Windows or with Office or something, you shouldn't have to install it.

What does "no longer works with this website" mean? Do you get bad output or just some response that says IE8 isn't supported? That might be bullshit, and I think you can put an arbitrary user agent in your requests in WinHTTP and pretend to be Chrome or whatever.

Turkeybone
Dec 9, 2006

:chef: :eng99:


Above, I would like the blue data bar to represent percentage completion (the first row is 33 thingees accomplished out of a goal of 78 thingees, so the bar should be 42% of the way across the cell). Right now the data bars how big that number is in reference to the others in the column. I feel like there should be a way to go about this (I can even hide the %s in some other column, but I'm not sure how to overlay those percentages over this number). Any suggestions?

esquilax
Jan 3, 2003

Turkeybone posted:



Above, I would like the blue data bar to represent percentage completion (the first row is 33 thingees accomplished out of a goal of 78 thingees, so the bar should be 42% of the way across the cell). Right now the data bars how big that number is in reference to the others in the column. I feel like there should be a way to go about this (I can even hide the %s in some other column, but I'm not sure how to overlay those percentages over this number). Any suggestions?

You're using conditional formatting data bars for this?

Both of the solutions that I can think of either require VBA or are very messy.

(1) You could have the top row fill up 42% of the way by setting the minimum bar length to Number=0 and the maximum to Number = 78/(33/78). This makes it think the maximum bar length is 184.36, and 78 is 42% of this which leads to the bar being filled up 42%.

However, due to the limitations of excel it doesn't appear you can use relative references for width of the bars, so this conditional format only works for a single row you specify. You could use a macro to set up a conditional format for each cell using the function:
.MaxPoint.Modify newtype:=xlConditionValueNumber, newvalue:= [insert a formula here]


(2) Another option is to split up your second column into 100 columns that are 1-2 pixels wide, then conditionally format them that way.

schmagekie
Dec 2, 2003
If you don't need the fancy bars, you could do something like =REPT("|",A1/78*100) and resize the column so that it would fit 100 characters.

schmagekie fucked around with this message at 20:11 on Oct 16, 2015

Turkeybone
Dec 9, 2006

:chef: :eng99:
Yeah, it's going to change as progress occurs each day, so while those are all cool answers, it's going to fall into "too much work for this one thing." Too bad I can't use relative references for it.

esquilax
Jan 3, 2003

Turkeybone posted:

Yeah, it's going to change as progress occurs each day, so while those are all cool answers, it's going to fall into "too much work for this one thing." Too bad I can't use relative references for it.

You could modify the macro solution I posted to update automatically whenever the sheet updates. It would take a VBA expert like 15 minutes to make the whole thing, but even a beginner should be able to get it done within a few hours. It's up to you whether that's worth it.

Turkeybone
Dec 9, 2006

:chef: :eng99:
Yeah I could get it done just fine, it's just that I have to email these out, and then I gotta convert to non macro for people with old lovely versions etc etc. It's not the code thats hard or anything just the users.

nielsm
Jun 1, 2009



I have a bunch of data items, each item has a starting time and an ending time, but otherwise there isn't any particular distinguishing features or values of each item. There is overlap between items. I'd like to make some sort of visualization of this, that emphasizes the overlapping.

Any suggestions for ways to accomplish this, inside or outside Excel?

(I could probably hack up some VBA myself, or even make a proper C# program, but would prefer not to.)

esquilax
Jan 3, 2003

nielsm posted:

I have a bunch of data items, each item has a starting time and an ending time, but otherwise there isn't any particular distinguishing features or values of each item. There is overlap between items. I'd like to make some sort of visualization of this, that emphasizes the overlapping.

Any suggestions for ways to accomplish this, inside or outside Excel?

(I could probably hack up some VBA myself, or even make a proper C# program, but would prefer not to.)

If you don't have too many points, like maybe under 100, a Gantt Chart might work.

You could also make a line graph, with the height being the number of simultaneous projects going on.

Or you could combine the two of them into one chart.

FAN OF NICKELBACK
Apr 9, 2002
Can someone help me out? For the life of me I can't figure out why regexp isn't replacing the input string:




code:
Public Function CountInString(IString As String, FString As String, Optional WildC As Boolean, Optional ICase As Boolean) As Long
'Counts the number of times a string appears within another string
'Istring = String to search in
'Fstring = String to find
'WildC = Boolean (whether or not wildcards should be counted as findings, default false)
'ICase = Boolean (whether or not case should be ignored, default false)

Dim objRegExp As Object
    Dim Tstring As String
    Set objRegExp = CreateObject("vbscript.regexp")
    With objRegExp
        .Global = True
        .IgnoreCase = ICase
        .MultiLine = True
        If WildC = True Then
            .Pattern = FString
        Else
            .Pattern = "(?:\b|^)" & FString & "(?:\b|^)"
        End If
        Tstring = objRegExp.Replace(IString, "")
    End With
    CountInString = (Len(IString) - Len(Tstring)) / Len(FString)
End Function
Here's what I'm using:

Istring = string drawn from a cell that contains " '=COUNTUNIQUES(A1:B6,RETURNUNIQUES(A1:B6),1) " minus the quotes and space after the first and before the last quote. before and after is a delimiter of ".AE0." which is part of the string.

FString As String = the same as above, minus delimiter before and after


this works with literally everything except for (so far) a cell value with line breaks in it, and the value mentioned above. It simple doesn't recognize / replace them.

Works with everything else I've thrown at it though, and I'm not 100% sure what's causing the hiccup.

Daedleh
Aug 25, 2008

What shall we do with a catnipped kitty?
I'm stumped at work.

I currently run a weekly report which goes out to a large audience in excel. I have to verify that an authorised user is opening the document and show only data that they're allowed to see. The security measures don't have to be perfect, but enough to stop anyone with medium-advanced excel/vba knowledge from accidentally getting access to the wrong information. If someone really took the time to hack the file to get at the information then it's not my problem and considered to be a behavioural issue on behalf of the user. The security measures have to be *reasonable*.

I've got 3 issues:
- Firstly there are a LOT of people still stuck using Excel 2003 while the most modern machines in the business have 2007. I write my report in 2007 but when I protect the workbook users with 2003 can't open it because it asks for a password. The password is the one used to protect the workbook and keep data sheets, formulas etc hidden. I obviously can't give out that password. Question 1 - is there any way for me to protect the workbook in Excel 2007 that will allow a 2003 user to open it without the password (just with the sheets/structure protected as per 2007)?
- Next issue - the company is migrating to Windows 7 next year and as part of that are locking down Macros altogether. Users can have an exception added to their profile to give them access to run macros, but my report goes out to a huge audience and at this rate there'll be more people needing the exception than those without. Question 2 - is there any way of getting a user ID (logon ID or any other identifier) without VBA?
- Even when people have the exception added to their profile, they still can't run macros which have a password protect on the VBA module. This is a significant problem since someone versed in VBA can read the code and change the Environ("username") to any user ID they like and get access to someone else's data. I've obfuscated the code, especially the key parts around usernames, as much as I can but I'm still not comfortable giving people write access to the code. I've even given it to a couple of users who I know have relatively advanced Excel skills and asked them to try and crack it and they couldn't. Even so - Question 3 - is there any way to set the VBA modules to read-only without using the protect project with a password option?

fosborb
Dec 15, 2006



Chronic Good Poster
If IT is locking down all macros then congratulations! now it's their problem.

SharePoint is your friend here. Barring that, have IT setup a shared folder, an AD group that can read it, an AD group that can write to it, and throw your data there.

Ragingsheep
Nov 7, 2009

Daedleh posted:

I'm stumped at work.

I currently run a weekly report which goes out to a large audience in excel. I have to verify that an authorised user is opening the document and show only data that they're allowed to see. The security measures don't have to be perfect, but enough to stop anyone with medium-advanced excel/vba knowledge from accidentally getting access to the wrong information. If someone really took the time to hack the file to get at the information then it's not my problem and considered to be a behavioural issue on behalf of the user. The security measures have to be *reasonable*.

Wouldn't it be better just to generate the different reports for each person as static data rather than just trying to hide the whole lot of code and formulas behind a false sense of security?

khazar sansculotte
May 14, 2004

I'm trying to help one of my colleagues with a project. We are pro-skub. We have a specific group of about 2500 people, and the goal is to convince them all to also be pro-skub over the next year or so. He's got a team under him having pro-skub conversations with people face-to-face. At the end of each such conversation, the target will be assessed as being pro-skub, anti-skub, or undecided. Some people may be spoken to several times, others may not be reached at all.

He wants to be able to spit out weekly reports showing the number of conversations had and the number of people assessed that week as being pro-skub, anti-skub, or undecided. He also wants each weekly report to show the cumulative total of pro-skub, anti-skub, and undecided people (presumably if someone is spoken to more than once, the most recent assessment governs), as well as the number remaining to be assessed.

Obviously this sort of task lends itself to a database, but he would want to be able to set something similar up on his own in the future without having to come bother me, and is much more comfortable using Excel.

Anyone have any clever ideas? The best I could come up with is still pretty clunky: each team member has their own sheet in workbook in which they enter in individual rows who they talked to and the skub assessment (using data validation to keep people from mistyping names), the project manager manually copies all the rows they want each week into a master sheet (or maybe a macro could do this), off of which a pivot table is built that can be used to display the weekly reports. On another sheet, I write some sort of lookup formula to search the master sheet bottom up to find the latest assessment of each person, giving a cumulative total.

fosborb
Dec 15, 2006



Chronic Good Poster
Sorry, I'm anti skub.

Daedleh
Aug 25, 2008

What shall we do with a catnipped kitty?

fosborb posted:

If IT is locking down all macros then congratulations! now it's their problem.

SharePoint is your friend here. Barring that, have IT setup a shared folder, an AD group that can read it, an AD group that can write to it, and throw your data there.

Ahahah yeah their problem. That's not happening.

It's not just that only authorised users can view the report, but the report shows them personalised location data. They're not allowed to see other locations. There's nothing highly confidential in there which is why the security is allowed to be so relatively lax but they shouldn't easily have access to other locations.

Ragingsheep posted:

Wouldn't it be better just to generate the different reports for each person as static data rather than just trying to hide the whole lot of code and formulas behind a false sense of security?

It would be over 800 separate reports.

Each person also has access to their location and all sub-locations, which in the report they can currently select via drop-downs. Sending separate static reports means each person could have up to 150 reports emailed to them and each separate report would need its own distribution list.

fosborb
Dec 15, 2006



Chronic Good Poster

Daedleh posted:

Ahahah yeah their problem. That's not happening.

It's not just that only authorised users can view the report, but the report shows them personalised location data. They're not allowed to see other locations. There's nothing highly confidential in there which is why the security is allowed to be so relatively lax but they shouldn't easily have access to other locations.


It would be over 800 separate reports.

Each person also has access to their location and all sub-locations, which in the report they can currently select via drop-downs. Sending separate static reports means each person could have up to 150 reports emailed to them and each separate report would need its own distribution list.

Excel isn't designed to manage fine grain permissions. No standard end user Office product is. Even Access can only handle hierarchy-based data permissions with after some vba hacks.

If IT is increasing base line security to the extent you can't use macros in your environment, you're screwed without moving to an enterprise solution. SharePoint could probably do it with some creative permissions and lists.

Otherwise it sounds like what you really need is something from SalesForce, NICE, or something equally expensive and in the cloooouuuud. Sorry for your loss.

schmagekie
Dec 2, 2003

Daedleh posted:

Ahahah yeah their problem. That's not happening.

It's not just that only authorised users can view the report, but the report shows them personalised location data. They're not allowed to see other locations. There's nothing highly confidential in there which is why the security is allowed to be so relatively lax but they shouldn't easily have access to other locations.


It would be over 800 separate reports.

Each person also has access to their location and all sub-locations, which in the report they can currently select via drop-downs. Sending separate static reports means each person could have up to 150 reports emailed to them and each separate report would need its own distribution list.
It seems like you're maintaining some kind of list of what people should be able to see, so why not create one workbook for each person with only the data they should see and email it to them?

Richard Noggin
Jun 6, 2005
Redneck By Default
Another potential alternative would be to use SQL Server Reporting Services to deliver the report and lock things down that way. SSRS can use an Excel sheet as a datasource.

Beef Hardcheese
Jan 21, 2003

HOW ABOUT I LASH YOUR SHIT


I have a list of about 10,000 audiobooks and their corresponding runtimes that I want to display as a chart. Excel insists on ordering them 1 hour, 10 hours, 11 hours, 12 hours... 2 hours, 21 hours, 22 hours, etc. It's doing this in the raw info as well. How do I get it to sort it by 1, 2, 3, ... 19, 20, 21, etc? I can't help but assume there's some formatting option that I haven't been able to find. Please have mercy on me, I'm just a liberal arts major. :(

ShimaTetsuo
Sep 9, 2001

Maximus Quietus
Do the cells literally contain the words "1 hour", "2 hours", "10 hours", etc? Because that is actually how you sort words: in dictionary (or "lexicographical") order. You could rename your column "Duration (hours)" and then store just the numbers (1, 2, 3,...) in the cells, then it will sort how you want. Probably easiest way to get these numbers out is to use text-to-column with a space delimiter, then delete the new column that just says "hours" a bunch.

If your cells actually DO contain just the numbers and they still sort wrong, you are storing numbers as text (the number 1 is distinct from the character "1", and so on). You can fix this by adding a column to the right of "duration" where each cell applies the function VALUE() to its neighbor to the left, and then just copy-paste value over the old column.

Note: formatting has nothing to do with it, sorting is done on the underlying value not the way it is formatted/displayed.

Beef Hardcheese
Jan 21, 2003

HOW ABOUT I LASH YOUR SHIT


ShimaTetsuo posted:

Do the cells literally contain the words "1 hour", "2 hours", "10 hours", etc? Because that is actually how you sort words: in dictionary (or "lexicographical") order. You could rename your column "Duration (hours)" and then store just the numbers (1, 2, 3,...) in the cells, then it will sort how you want. Probably easiest way to get these numbers out is to use text-to-column with a space delimiter, then delete the new column that just says "hours" a bunch.

YES! Everything is in text, and the Text to Columns / Delimiter is exactly what I needed to get all of this sorted out. Thanks!

fosborb
Dec 15, 2006



Chronic Good Poster

ShimaTetsuo posted:

If your cells actually DO contain just the numbers and they still sort wrong, you are storing numbers as text (the number 1 is distinct from the character "1", and so on). You can fix this by adding a column to the right of "duration" where each cell applies the function VALUE() to its neighbor to the left, and then just copy-paste value over the old column.

Alternative method: put the number 1 in a random cell, copy it, select the text you want to convert, and then paste special with the value and multiply options checked.

The Ass Stooge
Nov 9, 2012

a hunger uncurbed
by nature's calling
Is there a formula that I can use to display the value of a random cell from a range of cells? I have a list of items in text form and I'd like to be able to display a random entry from the list in another cell.

schmagekie
Dec 2, 2003

The rear end Stooge posted:

Is there a formula that I can use to display the value of a random cell from a range of cells? I have a list of items in text form and I'd like to be able to display a random entry from the list in another cell.

=INDEX(Range,RANDBETWEEN(1,ROWS(Range)),RANDBETWEEN(1,COLUMNS(Range)))

The Ass Stooge
Nov 9, 2012

a hunger uncurbed
by nature's calling

schmagekie posted:

=INDEX(Range,RANDBETWEEN(1,ROWS(Range)),RANDBETWEEN(1,COLUMNS(Range)))

Perfect, thanks so much!

raej
Sep 25, 2003

"Being drunk is the worst feeling of all. Except for all those other feelings."
I have a Macro I shamelessly stole that updates an adjacent cell with the time the cell was changed (See Below). It's working great! However, I need the times to always be in EST. How do I evaluate the user's Time Zone and put in the right NOW() so that times are in EST?

code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    Dim rCell As Range
    Dim rChange As Range
    
    On Error GoTo ErrHandler
    'Column to evaluate
    Set rChange = Intersect(Target, Range("E:E"))
    If Not rChange Is Nothing Then
        Application.EnableEvents = False
        For Each rCell In rChange
            If rCell > "" Then
                With rCell.Offset(0, -1)
                    'Add time to previous column
                    .Value = Now
                    .NumberFormat = "hh:mm AM/PM"
                End With
            Else
                rCell.Offset(0, 1).Clear
            End If
        Next
    End If

ExitHandler:
    Set rCell = Nothing
    Set rChange = Nothing
    Application.EnableEvents = True
    Exit Sub
ErrHandler:
    MsgBox Err.Description
    Resume ExitHandler
End Sub

ShimaTetsuo
Sep 9, 2001

Maximus Quietus

raej posted:

I have a Macro I shamelessly stole that updates an adjacent cell with the time the cell was changed (See Below). It's working great! However, I need the times to always be in EST. How do I evaluate the user's Time Zone and put in the right NOW() so that times are in EST?

The "Date" type in VBA doesn't carry any time zone information, so Now() returns the current time on the computer that runs it but not the corresponding time zone so you can't figure out how to adjust it just like that. You probably have to call down to some Windows API functions, like described here, which can be super annoying.

As an example, you can include the following code in a new module:

code:
Option Explicit

Private Type SYSTEMTIME
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
End Type
Private Type TIME_ZONE_INFORMATION
    Bias As Long
    StandardName(0 To 31) As Integer
    StandardDate As SYSTEMTIME
    StandardBias As Long
    DaylightName(0 To 31) As Integer
    DaylightDate As SYSTEMTIME
    DaylightBias As Long
End Type
Private Enum TIME_ZONE
    TIME_ZONE_ID_INVALID = 0
    TIME_ZONE_STANDARD = 1
    TIME_ZONE_DAYLIGHT = 2
End Enum

Private Declare Function GetTimeZoneInformation Lib "kernel32" _
    (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
 
Function GetCurrentTimeEST() As Date
    Dim localDateTime As Date
    Dim GMTDateTime As Date
    Dim ESTDateTime As Date
    
    'Get the current time as usual
    localDateTime = Now()
    
    'Get time zone info
    Dim TZI As TIME_ZONE_INFORMATION
    Dim DST As TIME_ZONE
    
    DST = GetTimeZoneInformation(TZI)

    'TZI.Bias is number of minutes to get back to GMT, then minus 5 hours
    ESTDateTime = localDateTime + TimeSerial(0, TZI.Bias, 0) - TimeSerial(5, 0, 0)
    
    'Return
    GetCurrentTimeEST = ESTDateTime
End Function
Then, in your code, replace the line that goes ".Value = Now" with ".Value = GetCurrentTimeEST()". The above is probably wrong during DST, not sure (but note that you have access to that information from GetTimeZoneInformation if you need to fix this).

raej
Sep 25, 2003

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

ShimaTetsuo posted:

The "Date" type in VBA doesn't carry any time zone information, so Now() returns the current time on the computer that runs it but not the corresponding time zone so you can't figure out how to adjust it just like that. You probably have to call down to some Windows API functions, like described here, which can be super annoying.

As an example, you can include the following code in a new module:

code:
Option Explicit

Private Type SYSTEMTIME
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
End Type
Private Type TIME_ZONE_INFORMATION
    Bias As Long
    StandardName(0 To 31) As Integer
    StandardDate As SYSTEMTIME
    StandardBias As Long
    DaylightName(0 To 31) As Integer
    DaylightDate As SYSTEMTIME
    DaylightBias As Long
End Type
Private Enum TIME_ZONE
    TIME_ZONE_ID_INVALID = 0
    TIME_ZONE_STANDARD = 1
    TIME_ZONE_DAYLIGHT = 2
End Enum

Private Declare Function GetTimeZoneInformation Lib "kernel32" _
    (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
 
Function GetCurrentTimeEST() As Date
    Dim localDateTime As Date
    Dim GMTDateTime As Date
    Dim ESTDateTime As Date
    
    'Get the current time as usual
    localDateTime = Now()
    
    'Get time zone info
    Dim TZI As TIME_ZONE_INFORMATION
    Dim DST As TIME_ZONE
    
    DST = GetTimeZoneInformation(TZI)

    'TZI.Bias is number of minutes to get back to GMT, then minus 5 hours
    ESTDateTime = localDateTime + TimeSerial(0, TZI.Bias, 0) - TimeSerial(5, 0, 0)
    
    'Return
    GetCurrentTimeEST = ESTDateTime
End Function
Then, in your code, replace the line that goes ".Value = Now" with ".Value = GetCurrentTimeEST()". The above is probably wrong during DST, not sure (but note that you have access to that information from GetTimeZoneInformation if you need to fix this).

This worked perfectly. Thank you so much!

Adbot
ADBOT LOVES YOU

raej
Sep 25, 2003

"Being drunk is the worst feeling of all. Except for all those other feelings."
Another weird one. I have a cell that's calculating a duration based on GetCurrentTimeEST()-<another cell>. When I change anything on the other cell, the formula recalculates (good). When I change any other cell on the form, the duration does not re-calculate (bad).

Is there an easy way to update this calculation when ANY cell changes value?

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