WorksheetFunction.Countif Line not reading my Address function - vba

I am trying to have a macros that will pull numbers no matter where they are pasted. I am using index match to pull these from an input. I have been successful in finding the "Addresses" for what I am looking for. How do I get functions to reference the Address in the Cells and not the Cells themselves?
It is right on the tip of my tongue and it is maddening. When I put
Application.WorksheetFunction.Countif(Indirect(Address(5,9,True,"Sheet2")), Range("C1").Value)>0= True Then
There is a function error. When I put in
Application.WorksheetFunction.Countif(Variable.Address(Extrenal:=True), Range("C1").Value)>0= True Then
There is a mismatch error
I have tried Indirect(address()) but when I plug this into Index match it says that there is an error. Index(indirect(address()),Match(Ref,Indirect(Address),0))
I have also been trying to use the address in a countif statement.
If Application.WorksheetFunction.Countif(Indirect(Address(5,9,True,"Sheet2")), Range("C1").Value)>0= True Then...
Also,
(Index(indirect(address()),Match(Ref,Indirect(Address),0))
I am getting as mentioned a mismatch error and a function error. I will take any method to fix either of these.

thank you all for your input. This is what I came up with.Dim SKU as Range;Dim SKUR as Range;Dim SKU1 as String;Dim Variable as String;Dim VariableR as Range;Set SKU = Worksheets("Sheets1").Range("A:AC").Find("Number");Set SKUR =SKU.EntireColumn;Variable - SKUR.Address(External:=True);SetVariableR=Range(Variable);SKU1=Application.WorksheetFunction.IfError(Application.WorksheetFunction.Index(VariableR,(Application.WorksheetFunction.Match((Range("C1").Value),VariableR,0)),0);Worksheets("Sheet2").Range("C5").Value = SKU1
Again, this is what I came up for using index match in VBA using an address range I found.Some reason it won't let me post it with the spaces so I am using semi colons to separate lines, please take them out when using this.

Related

Meaning of (052) at the end of text literal?

Really just a curious question.
Here are a few examples of the same concern that I have since they are being exported to the FM "REUSE_ALV_GRID_DISPLAY" for parameter "it_fieldcat".
ls_fieldcat-seltext_l = 'Material number'(052).
ls_fieldcat-seltext_m = 'Material'(053).
ls_fieldcat-seltext_s = 'Mat.'(054).
I tried removing the numbers on the right and executed the program but I didn't see any differences and I also tried to see what happens inside debug mode but it only fills the field with the string value, am I missing something or is there something that I wasn't able to notice?
I've been tasked to create a copy of a program which originally joins multiple tables and filters them according to the Parameters from the SELECTION-SCREEN and then shows the results in an ALV Grid Report, but for the use case of the copy it should instead populate a table in ECC that we will then be replicating to BW side. I have successfully copied and modified it accordingly but I can't seem to understand what the numbers beside the strings are doing.
Can someone please explain what their use is, would be very grateful to see a few examples.
Thanks!
The number in the brackets is a text symbol defined as a part of the text elements of the program. Using the syntax 'Literal'(idf) replaces these literals in the program if the symbol is in the currently loaded text pool.

What are the correct syntaxes for referring to a subform, and why is the recommended one producing an error?

I have the following two lines of code:
Debug.Print Forms!DocLoader!DL_RowBox!DLR_FileName.Name
Debug.Print Forms!DocLoader!DL_RowBox.Form!DLR_FileName.Name
The second one, which I have seen recommended in almost every VBA reference, including the answer being suggested from SO as I type this, follows this structure:
Debug.Print Forms![Form Name]![Subform Control Name].Form![Control Name].Name
These two lines of code should produce the same result. However, the second, recommended syntax throws error 40036, "Application-defined or object-defined error" unless I am in design view. I cannot use it at runtime, but I have never seen this limitation mentioned in any of the reference documentation or forum posts I have looked at. The first line, using only default parameters, seems to work no matter the context.
With the second line, I have tried just about every combination of bang and period I can, and I have also tried enclosing field names in brackets, but the common denominator is that as soon as I reference ".Form" the application throws an error. Even something simple like ".Form.Caption" has thrown an error. So what I would like to know is:
Are there any other correct ways of referring to a subform's form properties, since I need these as well as its controls
Why would the first line execute correctly while the second, recommended one does not seem to work?
Running the compiler appears to have fixed the issue.

Arrange Excel Cell Row Data under relevant columns

I have a large file of excel data where row data is not present under the relevant columns.
Name City School College Address
City:abc Name:abc College:abc Address:abc School: abc
City:abc College:abc Name:abc School: abc Address:abc
I have hundreds of such rows.
What I want is something like this :
Name City School College Address
Name:abc City:abc School:abc College:abc Address:abc
Name:abc City:abc School:abc College:abc Address:abc
I have identifiers before semicolon (:) in cell, but can't seem to match it to the column.
I have tried MATCH() Function for identifiers like School etc. but it can't work because Exact Match (Third field of MATCH() Function) won't work, other options can cause errors. Also Filter() doesn't seem to work either.
Kindly help me with an approach that can automate this. Can a formula be made for this or VBA code can work ?
I don't want to do so much manual work.
THANKS
EDIT
ANSWER:
Thanks Karpak for the answer. I just came up with the following solution before visiting your post.
For others, who are facing a similar problem, try this:
=INDEX(range, MATCH("SearcItem"&"*",Range,0), 1)
This will return the value of the cell after matching it up.
Happy Coding :)
Match with wildcard should work. Try with
=MATCH("Name:*",1:1,0)
=MATCH("College:*",1:1,0)
=MATCH("Address:*",1:1,0)
=MATCH("City:*",1:1,0)
=MATCH("School:*",1:1,0)
The above works for row 1. If you want to make it for row two replace 1:1 with 2:2 or if you want a specific cells, use A2:E2 etc.

Enter date into function without quotes, return date

I'm trying to write a function of this form:
Function cont(requestdate As Date)
cont = requestdate
End Function
Unfortunately, when I enter =cont(12/12/2012) into a cell, I do not get my date back. I get a very small number, which I think equals 12 divided by 12 divided by 2012. How can I get this to give me back the date? I do not want the user to have to enter =cont("12/12/2012").
I've attempted to google for an answer, unfortunately, I have not found anything helpful. Please let me know if my vocabulary is correct.
Let's say my user pulled a report with 3 columns, a, b and c. a has beginning of quarter balances, b has end of quarter balances and c has a first and last name. I want my user to put in column d: =cont(a1,b1,c1,12/12/2012) and make it create something like:
BOQ IS 1200, EOQ IS 1300, NAME IS EDDARD STARK, DATE IS 12/12/2012
So we could load this into a database. I apologize for the lack of info the first time around. To be honest, this function wouldn't save me a ton of time. I'm just trying to learn VBA, and thought this would be a good exercise... Then I got stuck.
Hard to tell what you are really trying to accomplish.
Function cont(requestdate As String) As String
cont = Format(Replace(requestdate, ".", "/"), "'mm_dd_YYYY")
End Function
This code will take a string that Excel does not recognize as a number e.g. 12.12.12 and formats it (about the only useful thing I can think of for this UDF) and return it as a string (that is not a number or date) to a cell that is formatted as text.
You can get as fancy as you like in processing the string entered and formatting the string returned - just that BOTH can never be a number or a date (or anything else Excel recognizes.)
There is no way to do exactly what you're trying to do. I will try to explain why.
You might think that because your function requires a Date argument, that this somehow forces or should force that 12/12/2012 to be treated as a Date. And it is treated as a Date — but only after it's evaluated (only if the evaluated expression cannot be interpreted as a Date, then you will get an error).
Why does Excel evaluate this before the function receives it?
Without requiring string qualifiers, how could the application possibly know what type of data you intended, or whether you intended for that to be evaluated? It could not possibly know, so there would be chaos.
Perhaps this is best illustrated by example. Using your function:
=Cont(1/1/0000) should raise an error.
Or consider a very simple formula:
=1/2
Should this formula return .5 (double) or January 2 (date) or should it return "1/2" (string literal)? Ultimately, it has to do one of these, and do that one thing consistently, and the one thing that Excel will do in this case is to evaluate the expression.
TL;DR
Your problem is that unqualified expression will be evaluated before being passed, and this is done to avoid confusion or ambiguity (per examples).
Here is my method for allowing quick date entry into a User Defined Function without wrapping the date in quotes:
Function cont(requestdate As Double) As Date
cont = CDate((Mid(Application.Caller.Formula, 7, 10)))
End Function
The UDF call lines up with the OP's initial request:
=cont(12/12/2012)
I believe that this method would adapt just fine for the OP's more complex ask, but suggest moving the date to the beginning of the call:
=cont(12/12/2012,a1,b1,c1)
I fully expect that this method can be optimized for both speed and flexibility. Working on a project now that might require me to further dig into the speed piece, but it suits my needs in the meantime. Will update if anything useful turns up.
Brief Explanation
Application.Caller returns a Range containing the cell that called the UDF. (See Caveat #2)
Mid returns part of a string (the formula from the range that called the UDF in this case) starting at the specified character count (7) of the specified length (10).
CDate may not actually be necessary, but forces the value into date format if possible.
Caveats
This does require use of the full dd/mm/yyyy (1/1/2012 would fail) but pleasantly still works with my preferred yyyy/mm/dd format as well as covering some other delimiters. dd-mm-yyyy or dd+mm+yyyy would work, but dd.mm.yyyy will not because excel does not recognize it as a valid number.
Additional work would be necessary for this to function as part of a multi-cell array formula because Application.Caller returns a range containing all of the associated cells in that case.
There is no error handling, and =cont(123) or =cont(derp) (basically anything not dd/mm/yyy) will naturally fail.
Disclaimers
A quick note to the folks who are questioning the wisdom of a UDF here: I've got a big grid of items and their associated tasks. With no arguments, my UDF calculates due dates based on a number of item and task parameters. When the optional date is included, the UDF returns a delta between the actual date and what was calculated. I use this delta to monitor and calibrate my calculated due dates.
All of this can absolutely be performed without the UDF, but bulk entry would be considerably more challenging to say the least.
Removing the need for quotes sets my data entry up such that loading =cont( into the clipboard allows my left hand to F2/ctrl-v/tab while my right hand furiously enters dates on the numpad without need to frequently (and awkwardly) shift left-hand position for a shift+'.

INDEXOF returning "Scalars can be only used with projections" error

Am trying to find whether one field is sub string of another field by using INDEXOF(f1,f2) > -1 where f1,f2 are both char arrays. But am getting error message as "Scalars can be only used with projections".
Is this error message because of, lack of support for two variables comparison in INDEXOF or something else? Can some one help with this?
Thanks in advance.