I want to write this code in LINGO. Basically this is a MILP which involves two decision variable. First decision variable "x" is calculated then if "x" is nonzero "y" is assigned to 1 otherwise "y" is zero.
Then value of "y" is used to calculate objective function.
Thanks for any help.
Related
I am making a macro which extracts information from SAP based on account and period. I have recorded it with the SAPGUI and it works fine with different variables (my goal is to have the same macro for different excel files based on a template). Where my problem comes from is when the number of accounts is changed, due to the fact that the set focus number is changing.
session.findById("wnd[0]/usr/lbl[70,13]").SetFocus
session.findById("wnd[0]/usr/lbl[70,13]").caretPosition = 8
Can someone tell me if its possible to make the number "13" in the brackets a variable and maybe how (the number is equal to count of the accounts + 12 and I have the number I need in a specific cell)
Regards,
Ivan
I would answer the first question Can someone tell me if its possible to make the number "13" in the brackets a variable like that
Dim pos as long
pos = 13
session.findById("wnd[0]/usr/lbl[70," & CStr(pos) & "]").SetFocus
I ve just used Vlookup Function.
Seems to work fine, but in some cases it doesn't return the very closest value.
Example : If your lookup value is 3.9, it will return 3 instead of 4. Any way to fix that?
According to MS Documentation on VLookUp function, you can set the 4th parameter to "TRUE if you want an approximate match".
In my opinion, the term "approximate" doesnt' mean "closest number", since you can also look up for string or dates.
To solve your problem, create a small function that loop through your data in B column, compare your value in A3 to values in Bx and save the value with the smallest difference.
I have a strange issue using Double type variables in my VBA Macros.
The Macro works fine when I test it on some systems, but causes a runtime error '1004' when tested on another system with different language settings.
Both systems use Office 2013.
I have a ScrollBar in a form, with values ranging from -50 to + 50.
Basically an indicator to increase/decrease the value of a range by -/+ 50%
The Macro is something simple like follows:
Dim multiplier As Double
multiplier = CLng(Me.DPScroll.Value) / 100 + 1
ThisWorkbook.ActiveSheet.Range("AB11:AB" & LR).Formula = "=H11*" & multiplier
When the DPScroll.Value = 0 (Multiplier = 1), the form runs file without any errors, but if it has a positive or negative value, it returns
Run-time Error 1004 : Application Defined/Object Defined Error
(On my system, both work fine)
So, I'm guessing the Multiplier is unable to take values in Decimal Points (Eg. 1.07 to increase by 7%)
(Less important issue)
It also causes a strange formatting error on another sheet.
I'm calculating the average of a few rows in a list box and pasting the value to a range. On some systems, the format is retained, but on others it changes and gets multiplied by millions and a Large number is displayed (like 10^E6 times)
Since this is restricted to some systems - are there any regional/language compatablity issues with suing "Double" variable type.
It is indeed a localization issue. As long as you use .Formula the regional settings are always standard US that means the multiplier has to be 1.07 (e.g. not 1,07).
But if the localization is German for example then if the multiplier is cast to a string it becomes 1,07 but .Formula needs the US standard 1.07.
Solution 1
Replace any comma , in multiplier to . using replace()
Solution 2
use .FormulaLocal to use the localized formula:
ThisWorkbook.ActiveSheet.Range("AB11:AB" & LR).FormulaLocal= "=H11*" & multiplier
But then you probably have to deal with other issues like e.g. =IF(A1=0,TRUE,FALSE) becomes localized too (e.g. for german): =WENN(A1=0;WAHR;FALSCH).
Solution 3
Another approach would be to write the multiplier into a named range, so you can use that name in your formula directly as following:
ThisWorkbook.ActiveSheet.Range("AB11:AB" & LR).Formula = "=H11*multiplier"
Therefore you can use ActiveWorkbook.Names.Add "multiplier", multiplier so you even don't need a helper cell for that named range.
But then if you change the multiplier any time, it also changes for every old formula in your sheets where the named range multiplier was used.
I have this formula, which takes two numbers in two cells, performs a division and places the value into a cell. However, this method causes the output to be a integer value.
wsProt.Range("E" & pdTableCount).Value = wsProt.Range("F" & pdTableCount).Value / wsProt.Range("D" & pdTableCount).Value
Is there a way to do this that will cause the value to be a value that provides for a decimal part without having to use an intermediary variable?
Also, I don't want the cell to be a formula, I just want the actual value for the division.
thanks!
I am a little stuck at the moment. I am working on an array of data and need to find a way to input column numbers into formulas.
-I have used the match function to find the corresponding column number for a value.
ex. "XYZ" matched with Column 3, which is equivalent to C1:Cxxxxxx
-now for inputing the C1:Cxxxxxx into a formula to get data for that particular column, I would like to be able to directly reference the Column 3 part, because I plan on using this workbook in the future and the column needed to run the calculation may or may not be column 3 the next time I use it.
- is there any way to tell excel to use a formula to tell excel which column to use for an equation?
so a little more detail, I have the equation
=AND(Sheet3!$C$1:$C$250000=$A$4,Sheet3!$B$1:$B$250000=$B$4)
instead of specifying to use column C, is there a way to use a formula to tell it to use C?
EDIT: more additional info;
"i am basically running the equivalent of a SQL where statement where foo and bar are true, I want excel to spit out a concatenated list of all baz values where foo and bar are true. ideally i would like it to ONLY return baz values that are true, then I will concat them together separately. the way I got it now, the expression will test every row separately to see if true; if there is 18K rows, there will be 18K separate tests.. it works, but it's not too clean. the goal is to have as much automated as possible. *i do not want to have to go in and change the column references every time I add a new data arra*y"
Thanks
You can use INDEX, e.g. if you have 26 possible columns from A to Z then this formula will give you your column C range (which you can use in another formula)
=INDEX(Sheet3!$A$1:$Z$250000,0,3)
The 0 indicates that you want the whole column, the 3 indicates which column. If you want the 3 can be generated by another formula like a MATCH function
Note: be careful with AND in
=AND(Sheet3!$C$1:$C$250000=$A$4,Sheet3!$B$1:$B$250000=$B$4)
AND only returns a single result not an array, if you want an array you might need to use * like this
=(Sheet3!$C$1:$C$250000=$A$4)*(Sheet3!$B$1:$B$250000=$B$4)
You could use ADDRESS to generate the text, you then need to use INDIRECT as you are passing a string rather than a range to the fomula
=AND(INDIRECT(ADDRESS(1,3,,,"Sheet3") & ":" & ADDRESS(250000,3))=$A$4
,INDIRECT(ADDRESS(1,2,,,"Sheet3") & ":" & ADDRESS(250000,2))=$B$4)
Obviously replace the 3s and 2s in the ADDRESS formulae with your MATCH function you used to get the column number. The above assumes the column for $B$1:$B$25000 is also found using `MATCH', otherwise it is just:
=AND(INDIRECT(ADDRESS(1,3,,,"Sheet3") & ":" & ADDRESS(250000,3))=$A$4
,Sheet3!$B$1:$B$25000=$B$4)
Note a couple of things:
You only need to use "Sheet3" on the first part of the INDRECT
Conditions 3 and 4 in the ADDRESS formula are left as default, this
means they return absolute ($C$1) reference and are A1 style as
opposed to R1C1
EDIT
Given the additional info maybe using an advanced filter would get you near to what you want. Good tutorial here. Set it up according to the tutorial to familiarise yourself with it and then you can use some basic code to set it up automatically when you drop in a new dataset:
Paste in the dataset and then use VBA to get the range the dataset uses then apply the filter with something like:
Range("A6:F480").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Sheets("Sheet1").Range("A1:B3"), Unique:=False
You can also copy the results into a new table, though this has to be in the same sheet as the original data. My suggestion would be paste you data into hidden columns to the left and put space for your criteria in rows 1:5 of the visible columns and then have a button that gets the used range for your data, applies the filter and copies the data below the criteria:
Range("A6:F480").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Sheets _
Range("H1:M3"), CopyToRange:=Range("H6"), Unique:=False
Button would need to clear the destination cells first etc, make sure you have enough hidden columns etc but it's all possible. Hope this helps.