I want to but an OR in this IF statement. For example IF cell="2" OR IF cell="4" OR IF cell="hello".
Can you help me? In the current code i have only an IF cell="2".
Cell.FormulaR1C1 = "=IF(left(RC[2],1)=""2"",""delete"",""1"")"
Try this (untested but hopefully will work):
Cell.FormulaR1C1 = "=IF(OR(left(RC[2],1)=""2"",left(RC[2],1)=""4"",left(RC[2],1)=""hello""),""delete"",""1"")"
Related
I'm working with data from Bloomberg. My code is :
Sub Code_Fin()
Sheets("SPX").Cells(2, 3).Formula = "=BDS(""SPX Index"", ""INDX_MEMBERS"",
""END_DATE_OVERRIDE=20210810"",""cols=1;rows=1000"")"
End Sub
Do you know please, how replace the ""END_DATE_OVERRIDE=20210810"" by something like ""END_DATE_OVERRIDE=today()"" ? I would like to change the date automatically.
Thank you !
For various reasons, I need to concatenate a text of the form [NAME].Value by changing the value of NAME to an inputbox entry.
Something like this:
Sub example()
data_in = InputBox("Give me something: ")
mystring1 = "[" & data_in & "].Value"
a = Evaluate(mystring1) 'I know this is wrong, but I don't know how to do so.
End Sub
I know it can be done in other ways, and the example in which I want to use this code is not exactly this one, and while it can be done in several ways here, in the original code it can only be done this way.
I want, based on the input in the imputbox, to concatenate the string in whatever way, and subsequently cast that string as code to store the value in another variable, to be used later in the code.
I am not able to get VBA to read the string text as code. I have seen that there is a way that consists of creating a macro from this first macro, execute it, and then delete the recently created macro. The problem with this solution is that doing that I can't save the variable when returning to the initial macro (I don't want to use global variables).
Surely there must be a way?
Thank you very much.
EDIT: The code above returns Error 2015
In order to use a string as if it was code, you can use the evaluate function (exists in most languages)
The official documentation mentions this example:
[a1].Value = 25
Evaluate("A1").Value = 25
trigVariable = [SIN(45)]
trigVariable = Evaluate("SIN(45)")
Set firstCellInSheet = Workbooks("BOOK1.XLS").Sheets(4).[A1]
Set firstCellInSheet = _
Workbooks("BOOK1.XLS").Sheets(4).Evaluate("A1")
I have figured out the easiest way to do it, sorry for posting the question so soon.
Thanks to #Andreas for the solution. I'll write it here in case than could be useful to someone.
Sub example()
data_in = InputBox("Give me something: ")
a = Range(data_in).Value
Debug.Print a
End Sub
In the end the simplest thing is the last thing you try...
I have the following code
=IFERROR(IF(INDEX('Combined Page'!I:I,(MATCH('Load & Unload (7)'!A272,'Combined Page'!A:A,0)))>=35,"Completed","Available"),"")
Instead of having A272 I wanting to use A then row()
How would I write this?
Thanks
As suggested
=MATCH(INDIRECT("'Load & Unload (7)'!A"&ROW()),'Combined Page'!A:A,0)
Works. Thanks
I am trying to execute the following string as code using Evaluate but get Error 2029. Anyone know why?
Help much appreciated.
Calculation = "Format(""21/08/2012"", ""MMM"")"
Value = Evaluate(Calculation)
Try instead
Calculation = "TEXT(""21/08/2012"", ""MMM"")"
EVALUATE converts formulas to results, and FORMAT is a VBA function. The formula equivalent is TEXT.
You can also skip the evaluate and use the FORMAT function on the date directly.
You can use most worksheet functions in VBA directly with Application.WorksheetFunction. - for example - try this out:
Sub DateExample()
Dim StringTest As String
StringTest = Application.WorksheetFunction.Text("12/08/2012", "MMM")
Cells(1, 1).Value = StringTest
End Sub
Good Luck
I am trying to continue code to the next line. I have tried the (space)_ method and get compile errors, expecting seperator or expecting line # etc.... Have also tried & on next line. My code looks something like this.
Set rangeLimit = Range (A1:A9,B1:B9 on through M9:M37")
I need to move to the next line and continue this range all the way through Y9:Y37
I have looked on several help sites and all I have seen point to the things I have already tried. I am sure I am missing something simple. Any help would be greatly appreciated.
Set rangeLimit = Range("A1:A9,B1:B9," & _
"M9:M37")
space underscore works for me
Set rangeLimit = Range("A1:A9,B1:B9", _
"M9:M37")