Best short examples of the need for Excel VBA [closed] - excel

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Here's one for Joel...
I am looking for ways to demonstrate to an Excel user (with no programming experience) how learning some Excel VBA can make their life working with Excel a little easier.
First thoughts are to use an example that replicates manual tweaking of a spreadsheet, such as one click conditional formatting of all the data. For example: highlighting all the numbers red, orange or green according to user input thresholds coupled with some other derived data such as current business week.
I am hoping that such a short VBA example should not be too difficult to grasp for someone who has never written a line of code before, and hopefully make a case for trying to learn a bit of Excel VBA.
However, with this example the time taken to code it is not significantly quicker than applying the conditional formatting manually in Excel. So I would be interested to know if anyone in the community has any more elegant examples that demonstrate the advantages of using Excel VBA.
Ideal examples would have the following characteristics:
Significant time savings (large T, where T = time for manual procedure / time to code).
Non-abstract, everyday spreadsheet examples.
End results that can not be easily achieved manually.
Achievable with short, basic VBA code.
Bear in mind that the target audience is taking their first steps into programming.

If you can, watch them use Excel for a 1/2 hour and you'll find the perfect opportunity. When they open that one spreadsheet, autofit all the columns, format col A as a date, right justify col J, delete rows 2 through 5, and change the print orientation to landscape then you've found a winner. Have them do it again, but with the macro recorder on. Then replay the macro recorder.
By working with something they use in real life, it will have more impact.
You don't have to save them 1/2 hour a day with the first shot. Save them 30 seconds of drudgery on something they'll use and they'll start thinking of all the things they want automated. In my experience, they'll go overboard rather quickly. In no time, they'll want Excel to go fill out a web form, import the information, and get them a coffee.

Create your own "function" with VBA that you can use like another function from within the sheet.
You can do things that are not possible in plain Excel, or very hard to implement or reuse.
An example:
In VBA create a new module, add code like this:
Public Function SizeOfFile(a As String)
SizeOfFile = VBA.FileLen(a)
End Function
And you can now use SizeOfFile in a formula in a cell.
If cell A1 contains the name of a file, B1 fill with =SizeOfFile(A1) to get the size.
Also
You can show recording (and editing) a macro, to repeat steps that you do often.

Are the people in the target audience power users?
If so, how about combining data from multiple workbooks using external references? I'm not sure if external references are the best way to do this, and I'm not sure how difficult this would be for someone new to VBA, but that's what I ended up doing in the past.
Example 1
There are many excel files following a naming convention:
c:\data1.xls
c:\data2.xls
c:\data3.xls
I wanted to be able to enter the ID numbers in one column and have a VBA to get the data for me for all the other columns. I chose to do this with external references because then I didn't need to worry about opening and closing files and worrying about whether or not those files existed.
I wanted the result to look like this:
id data hyperlink
1 extRefA1 c:\data1.xls
3 extRefA1 c:\data3.xls
500 extRefA1 c:\data500.xls
I didn't need VBA to make the hyperlink, but I couldn't find an easy way to make external references without VBA. I tried using INDIRECT, but the referenced workbook had to be opened for INDIRECT to work. So, I used VBA to create the external references.
Example 2
This one is similar to Example 1, but I had to combine different chart data.
The data in each excel file were in columns:
X Y
1 5
2 10
3 5
4 60
I wanted the combined chart data in rows:
1 2 3 4
data1 5 10 5 60
data3 30 60 4 2
data500 25 45 20 5
So I made a VBA that put a formula array containing an external reference in a TRANSPOSE.
The data1 formula array looked something like this:
=TRANSPOSE('c:\[data1.xls]Sheet1'!$B$2:$B$5)
I don't know how others use Excel and VBA, but these proved to be extremely useful to me.
Francis

My first tentative steps into VBA were taken after I joined a company and saw one of my new team spending 30 minutes each morning compiling a report from a list of about 1,000 items that needed auto-filtered in different ways to produce the required counts. A few hours mucking about with VBA had the task down to a button click and about a second.
Anything like this that involves a loop is going to satisfy your first criteria of a significant time saving. Perhaps a task that involves extracting the area codes or house numbers from a list of 200 phone numbers or addresses?

Here is an awesome msdn link for this question.
http://msdn.microsoft.com/en-us/library/aa203714(office.11).aspx
has everything you need for a short preso.

Related

How to make formula results static [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Or perhaps another way to look at it would be how to make a formula result static...
The problem: I have created an invoicing/booking solution for my business using excel sheets, I have many sheets such as delivery addresses, client data and addresses, bookings, jobs, invoices and so on. There are many many formulas which do different things at different times, for example, if a client books a service for an address the sheet will auto calculate the cost of the service through a series of formulas and IF statements. But if I change any of the data a pricing formula relies on it will recalculate all formulas relating to that data change, an example a customer books today at $100, on their next booking I give that customer a permanent discount of $25 on all future bookings, once I add the discount against the customer, the pricing formulas recalculate all the formulas which could cause obvious accounting issues.
I know wrapping time and date stamps in an if statement can stop a similar issue occuring and that their is also macros that can be written to time stamp on an event, can anything be done with the formulas or is there another workaround to this issue, ive almost got all the functionality I need without using any macros which in itself is an achievement but on the other hand if a macro is the only way, any options it would be great.
In short can anyone offer any solutions to making formula results static to those cells, ie rewrite the formula with the result itself so the result is permanent and therefor only editable manually.
I havent included any screenshots as I couldnt really see what would be relevant, but if there are any bits you'd like to see or have more info on to help answer feel free to ask
It's hard to give you specific advise to implement a non-trivial change on a complex workbook-based pricing application that we have no knowledge of. But here goes...
Make up a new table called CustomerDiscount. That table should have three columns: CustomerID, Date, and Discount. Then rewrite your formulas in your 'transactional' sheet where you are taking booking or whatever, so that they match the CustomerID and Date against the CustomerDiscount table and so pull out the relevant discount that applies after date x.
You can likely find generic examples on Google. The concepts involved here are 'Approximate VLOOKUP' or 'Approximate INDEX/MATCH' so try those search terms in google, and perhaps add something like 'look up next highest date' or similar. I can't give you any more specific advice than that without you having a go at implementing this new 'CustomerDiscount' structure, having a crack at it yourself, and then posting back a much more specific question if you get stuck.
Relying on some trigger to either calculate or not calculate a result is NOT the way to go, because you will always have a nagging fear that something might have been recalculated when it shouldn't have been, and vice versa. You need a audit trail. Without one, you're a sitting duck.
There are 2 potential solutions: 1. You can go to your formula tab, to the calculation section, and select to "manual calculation" on/off. It's default is on. But if you turn it off, you can change anything and keep the values you have. However, you will have to hit "calculate now" every time you make a change and need it updated, this is very easy to forget to do.
Secondly, you can right click on any of the work book tabs at the bottom and select "Move or copy", and you can make a copy to a blank workbook. You can then save that workbook as their invoice/book.
Also, you can copy a cell, or range of cells, then right click and "paste values" in which the formulas are replaced with the values you are currently seeing. You wouldn't want to do this on your master workbook.
Contact me if you think a macro automating this would be useful. Hopefully some or all of these ideas are useful to you! Please leave a comment if you need further explanation.

Calculating Multiple Averages

It's my first time posting a question to this forum. Though I have found answers here many times before, I have been unable to find a solution to my current predicament.
I work in a call center and each week I need to analyze data from the thousands of call that took place over the week. I'm new to programming in Excel-VBA but I've been able to get pretty far.
The data is produced by a third party program and the format is nigh unreadable. Much of the programming I've done so far has been geared towards making the data more organized. Now, I'd like to get into more analysis.
The data is arranged by employee number (NOT in order, though). Each employee takes several calls over the course of the week, some for which the customer takes a survey. It's the survey scores I want. I want to take the average of all the surveys for each employee and then display that average in the same row as each of the entries.
Example
The yellow highlighted area is what I want to add. Any ideas? Thanks for any help in advance!
No need for VBA. If you have the supported version of Excel you can use AVERAGEIF. If not you can use below formula.
Enter as an array formula by pressing Ctrl+Shift+Enter when exiting cell edit mode (instead of just enter).
=AVERAGE(IF($A$2:$A$13=A2,$B$2:$B$13))
Then copy down for all rows.

Marking an Excel Spreadsheet with a value range

I teach a budgeting course for my professional association. As part of that course, students are required to submit a draft budget as part of their marks. The budget template that I have to use is kindof set in stone. The association offers it's courses at various college locations and I can't just arbitrarily change it's contents.
That being said, marking this assignment is a pain in the neck! I'm looking for an easy way to be able to compare the values in a cell, and then mark it correct or incorrect, if it is within an expected range..
For example, students are required to estimate the expenses for the current year. If their estimate is within $200 +/- of what the answer key states, then I would mark their answer correct.
I am not a coder by trade, but rather an armchair coder who will search out and self teach what I need to solve my problem, so I'm not afraid of a bit of homework myself. I have not been able to find any solution so far. Right now, my students submit their assignment hardcopy, and I manually mark their spreadsheets. Tedious to say the least. Any searches I try to perform for academic marking of an Excel spreadsheet only return solutions to use Excel as a tracking tool for student marks, which is not what I'm looking for.
My college uses Desire2Learn as their online platform for content delivery, and students can submit their material electronically, I want an easy way to determine if they have completed the spreadsheet correctly.
Any help, or pointers in the right direction would be greatly appreciated!
There are probably several ways to tackle this problem but this might be something simple if the layout of the sheets doesn't change. You could create a worksheet with 3 sheets.
1. a sheet to copy their work into
2. "Master" sheet with the correct answers
3. "Grading" sheet that has formulas that calculate the difference (possibly within a range). For example IF(ABS(Sheet 1!B20 - Sheet 2!B20)>200,"Correct","Incorrect"). Calculates the absolute value of the difference between the same cell address on 2 different sheets then compares to the expected answer and returns Correct or Incorrect.
You would still have to copy their work into your master worksheet one at a time. Remember this only works if their worksheet layout doesn't change.
Post a rely along with a sample of the data if you need something more flexible.

Excel spreadsheet crash: Thousands of cells become "#NUM!" simultaneously [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
A massive Excel spreadsheet (60 tabs, ranging to 1,000 x 68 cells each), that I've created to analyze traffic pricing in New York City, crashes when I input values outside of a narrow range in one particular cell. By "crashing" I mean that a huge number of cells -- probably tens of thousands -- return "#NUM!" simultaneously.
As you've guessed, the spreadsheet is recursive in that there are hundreds (thousands?) of instances in which data are passed back and forth among different cells ... as must occur in processing travel choice (e.g., raising road tolls reduces auto trips, but the resulting improvement in traffic flow attracts auto trips, which then worsens traffic flow ...).
Is there a way in which I can "slow down" the calculations in order to see where the #NUM! results first appears? Lacking that, I've spent a good deal of time fruitlessly trying to track down the formula or algorithm that causes the initial #NUM! result, which then infects all of the others, rendering diagnosis impossible.
The spreadsheet, approximately 4 MB, may be downloaded via this link: http://www.nnyn.org/kheelplan/BTA_1.1.xls. The cell that leads to the collapsing values is F444 in the "Taxis" worksheet. Its current (saved) value is unity (1.0). Raising it to 4.0 or even some lesser values will make the spreadsheet collapse ... from which it cannot be rebuilt.
I should say that I'm a mathematician and not at all a programmer. Indeed, I'm more of a "numbers savant" than a mathematician.
Thanks in advance. I'm new to this site and am impressed with it.
In Excel 2010 (but maybe after 2007 all has this function) there is an Evaulate formula button at the Formula Auditing group on the Formula tab.
You select an #NUM! field, and use it on, you can go in to the formula, and Evaluate the formula (calculate a segment of an formula). Also, you have in that group a few helper function, like trace dependents/precedents.
EDIT1:
Oh, and you get this error (#NUM!) if:
You calculated somewhere too big number ~ 1E+308 or bigger in a field
You want to do something like this: 0^0
You get somewhere (in one previous field) this error #NUM! which you want to use
EDIT2:
Now, I found your problem (maybe), you want somewhere to calculate too big number with itaration. If you set Maximum Itarations to 1 it hasn't got #NUM! errors. (you can find this at Excel options - Formulas tab)

excel: charting with unknown number of data

Let's (for discussion purposes) say that I have x and y data in 2 columns. They're some measured data which, several times a day, a few of them are added (usually 4 times a day).
Now, I wish to plot y=f(x) (linear scale), but the problem is since data is constantly added to determine the number of points which will go in the plot. Always creating a new plot and then formatting it and all, is troublesome for ... reasons.
Is there a way to do this using excel's build in functions ? Should I use vba ? I tried googling, but I don't know what to search for. I'd appreciate any help on this, even if its just a point in the right direction.
Is there a way to tell excel, use all points in this column until you hit an empty cell ?
You can do this without any VBA. Jon Peltier has an example by Debra Dalgleish on his website:
http://peltiertech.com/Excel/Charts/DynamicColumnChart1.html
It can be pretty frustrating to Google anything related to Excel because there is so much junk out there, but I've found that if there's something "obvious" that you know shouldn't be so hard, one of the various "MVP" sites will have covered it.

Resources