Excel multiple goal seek macro code error - excel

I am using a simple macro found in internet for Multiple Goal Sheek in Excel 2010. The link is here
The point is that the macro is working in the example test MultipleGoalSeek(KB19).xls.
given in that link.
But when I try to apply it in my excel sheet, it only solves the first Goal Sheek problem, leaving the others un-calculated. I have no idea why although the macro seems pretty easy (maybe because they are not integers?)
I attach my excel problem with the macro.
Thank you

Hmmm .... this is a very early piece of brettdj code, it dates back to my beginner days a decade or so ago. And it shows .... !
The issue is in the third last row of the code, contrary to the instructons in the file, it was designed to work over columns only (I was running a time-based inventory adjustment at the time)
Change
For i = 1 To TargetVal.Columns.Count
to
For i = 1 To TargetVal.Cells.Count
And it works fine on your sample
I will work on the orginal code to run with variant arrays.

Related

Excel UDF not working on another computer

I have searched the internet and Stack Overflow, but couldn't find an answer to my problem.
I defined a UDF in Excel, it's saved in a module in an .xlam Add-In. The UDF works perfectly fine on my computer. Now I'm trying to use the workbook which uses the UDF on another computer (in a different language) with the same .xlam Add-In active. However Excel suddenly references the entire path to the add-in file as an "absolute path" instead of only showing the function name itself. The result is a #NAME? error because Excel doesn't find the UDF.
How I have written the VBA Code
How it should look
How it looks on another computer
Has anyone had this issue and found a solution for it? I could try to find a workaround without the UDF function but I'd prefer that it works this way. Another time the situation might be more complex ...
The problem with your UDF is the location of the .xlam file. You can find information on dealing with that by following the link in the comments above provided by Christofer Weber.
Having said that, I think it may be more beneficial for you to use the built-in formula that excel has for this which is EOMONTH()
EOMONTH() can be used to return both the last day of a month and the first day of a month (by finding the last day of the previous month and adding 1)
You can find more information on EOMONTH() here https://support.microsoft.com/en-us/office/eomonth-function-7314ffa1-2bc9-4005-9d66-f49db127d628

Dynamically merge tables in Excel

I've found several sources that appear to give me a solution to my need, but each one has come up short. I think my solution is in using VBA UNION; however, I am a complete VBA noob, so I feel like I shooting in the dark. Here is my need.
I have a worksheet with multiple tabs.
Each tab has the same headers for the first 10 columns.
I'd like a sheet that is a summary of the first 10 columns of all other sheets combined.
I thought if I made each sheet a table and named each, I could create a range of ranges and then just call that combined range on the summary tab. My thought is there a solution somewhere with Union here, but I don't know enough to know if that's right or not.
I need basically what this solution is, but rather than it running on a run command and doing a copy/paste, the result just needs to dynamically update. https://danwagner.co/how-to-combine-data-from-multiple-sheets-into-a-single-sheet/
As a Google Sheets user, this is super simple, but I have to use Excel for this. I feel like there must be a simple solution that I am just completely missing. In Sheets I'd have just done ={range1;range2;range3;etc} and I'd have had my output, if that helps someone get what I need.
Any help here is very much appreciated.
Part of what is great about VBA is that it is an event-driven language, so you can set your code to run every time a cell is changed, workbook is saved, etc. instead of having to press a button. I recommend reading up to section 3.1 of Excel VBA Events - An Easy Guide where it explains how you can use:
Private Sub Worksheet_Change(ByVal Target as Range)
CombineDataFromAllSheets
End Sub

Referencing a linked file from INDEX() in Excel (Office 365)

I've got a collection of about 40 Excel worksheets. They store information about the number of hours that people have spent working on different projects, with dates across the top row from left to right and project names down the first column. Each member of the team has their own separate worksheet.
I'm making a new worksheet that will add up the number of hours each person has spent on a specific project.
I'm using this formula to add up all the numbers in a particular range of a linked file:
SUM(INDEX('S:\path\to\folder[Username_2017.xlsx]Daily'!G:JG,JOB_ROW,0))
JOB_ROW is the row containing the numbers I want to add up. Columns G:JG cover 1 Jan - 31 Dec. Username_2017.xlsx is different for each of the 40 people.
The problem is that the formula only works if I create it by hand. I can't find any way to use a dynamic reference to the filename, which gets very tedious with 40+ files to reference. I thought this might work:
SUM(INDEX(INDIRECT(C3),JOB_ROW,0))
...where C3, C4, C5 etc. would contain automatically-generated filenames and references. But it doesn't work. I get #REF!. And Excel doesn't prompt me to link the files -- which suggests to me that it will never work this way.
I've also found that even when the spreadsheet is working properly with the manually-entered formulae, if I save it and re-open it then Excel tries to be helpful by stripping out the formulas and replacing them with the text #REF!.
Is it possible to do what I'm trying to do? Or do I need to learn some VBA?
I should point out that I've largely avoided using Excel in my career so far -- so if there's a better way to achieve this then I'd love to hear it.
Thanks in advance for your help.
ian0411 gave the simple answer to this question in the comments above: the answer is "you can't do that".
If he wants to post that then I'll accept it as an answer -- but for the benefit of anyone else reading this question and looking for alternative options, here's what I tried and what worked:
VBA
I wrote some very simple VBA using GetObject() to open and read from each of the workbooks. It worked, but a) it was very slow, and b) it seemed to keep all the files open as long as Excel was running, which caused other problems. It also crashed a lot.
I gave up on VBA.
Automating the filename replacement
The next option I tried was to have a column of filenames in Excel, with a column next to it containing the formula that I wanted to run on each file. Instead of putting the linked filename in the formula, I put a unique placeholder ('XXXXX' or whatever).
Then I made a little macro that (for the currently selected row) did a search and replace across the row to change 'XXXXX' to the filename in column A. I had to run the macro 40 times to cover each file, but I only had to do that process once. When I add a new file to the list, I'll just add a new line, copy the formulas, and update the filename.
I've now got a spreadsheet which works perfectly when the linked files are closed, and which doesn't rely on VBA.
Perhaps if my VBA skills were better I could have written something less flaky -- but doing it all with INDEX() seems like the fastest, most elegant, and most reliable solution.

Handling complex numbers in Excel spreadsheet

I doubt an Excel spreadsheet can handle this but it's worth asking, since I have been trying and searching for a long time with no success.
Entering this into a cell:
=complex(abs(-1.5*(-1.5)^(-1.5))),0)
and the cell output is #NUM!
The output should be: 0.8164966
I played with this a bit and didn't get anywhere - this article may explain why.
Link
it's complicated, and I think it's more than an excel problem
The following pdf has a nice write-up for using complex number functions in excel.
https://ccnet.stanford.edu/cgi-bin/course.cgi?cc=ee246&action=handout_download&handout_id=ID11300955936304
Seems like you have made a mistake inserting the parentheses.
The correct form is:
=COMPLEX(ABS((-1.5)*((1.5)^(-1.5))),0)
=0.816496580927726
This runs well in Excel 2013.

What is the easiest way to automate Excel tasks

If I need to automate a series a task on an excel sheet like
remove all rows where column 3 contains value "asdf"
remove column 7 and column 9
sort according to column 4
etc.
What is the easiest way of automating such tasks in excel? I think it would recording a macro but sometimes macro have to be edited a lot to actually make them work and even then macros stop if the excel sheet has a variation. Editing macro scripts could be a time taking process which becomes inefficient for such tasks. The automation is required since number of excel sheets will be a lot. Can you suggest an easier way ?
As long as, you have the activities defined - Macro is still the better thing to look for.
There could be some things that could change.
Please explain the problem with the help of code.
If you have defined the steps with a few variables, it should be easy to write a macro that wouldn't stop in case of variation.
Please post the code and describe in detail what you would want? which point does it stop, in case of variation? What would you like the code to do?
EDIT: Alternatively, you can write code in VB6/.net (c#/vb.net)/Python for automation.
If you record these steps using the macro recorder it will work fine, these are the ideal types of things for the macro recorder as the parameters (i.e. your sort by and delete conditions) are always the same. Just make sure that you always import/paste the data to the same place!
Thanks
Ross

Resources