I am trying to create a columns which looks at another column called software name, if this column contains a certain word the new column will say what it is. so for example chrome is found in the software column, in the new column this will say Google and then if the software column contains firefox, the new column will have mozilla. Ive tried using the contain and search function and i come out with #ERROR all the time.
Anyone got a solution??
Pseudo code
=IF(CONTAINS([softwareName],"Chrome"),"Google", IF(CONTAINS([softwareName],"Firefox"),"Mozilla","Unknown"))
This should work:
=IF(IFERROR(SEARCH("Chrome",[SoftwareName]),-1) <> -1, "Google",IF(IFERROR(SEARCH("Firefox",[SoftwareName]),-1)<>-1,"Mozilla", "Unknown"))
The Search function in DAX actually returns an error if it cannot find the string you provided. Otherwise it returns the starting position where the string can be found. See the DAX reference for more details. So I used iferror to catch the error returned when it can't find the string. If it doesn't find the string (and therefore Search returns an error) , it returns -1 instead, which cannot possibly be a valid start position in this context. If the search for "Chrome" is not -1, "Chrome" was found so the value is "Google". Otherwise, it moves on to the next if statement.
Related
I am writing a program, and I need to be able to check whether a certain 'tag' exists, by looking at all the 'tags' in the column 'CowTagMain' of the 'CowTable' table.
The code I am using is,
DLookup("[CowTagMain]", "[CowTable]", "[CowTagMain]") = Tag ...
Where tag is a String, TagMain is the column, and MainTable, is the table I am fetching data from.
I am getting inconsistent results, when I try this with 18C, it returns true. While if I try this with 18, it returns false.
I would assume I am fundamentally misunderstanding how to use DLookup, but after searching the internet for hours I cannot understand what I am doing wrong.
Even just pointing me in the right direction would be very appreciated! I am new to working with Access and VBA.
The search criteria is not within the function WHERE CONDITION argument.
The field is text type so need apostrophe delimiters.
Consider:
If IsNull(DLookup("[CowTagMain]", "[CowTable]", "[CowTagMain]= '" & Tag & "'")) Then
Hi I am really new to VBA Macros and would appreciate any help on this matter.
I need to write a macro to change the value of a column to 'checked' based on different search criterias. My requirement is that one of the columns values must be automatically marked as checked based on search criterias which will search for existence of serial nos contained in a string in one column inside string values of other columns.
Please help me in creating a macro to accomplish this task.
I am sorry to say that I cannot share the code or attach a screenshot to further explain the scenario because of confidentiality reasons.
Detailed explaination
Column to be modified : Comments (initially blank)
Columns used for search criteria : Can be any column in the existing table.
Search criteria:
A substring from the reference column (basically a number with 6 digits will be selected as the search key)
Note : There is no specific format followed by this column (and we can do nothing about that) eg: In one column the entry will be 35567890-DEF-GHJ while in another it will be like Ref:35567890-- and in another column field it will be like CEK 35567890.
The substring must be checked not only for the entries in the same coulmn but with the contents of the entire table. Basically it is like the find function in the excel.
If a match is found I need to add up the values in the debit and credit entries and see whether the result is 0. If the result is zero, I need to enter 'checked' in the comments field that allows string values.
This is not one complete macro but still does the work.
Macros where used only for extracting the product code. For the remaining processes I used existing functions as in, performed a comparing function on the net amount and then used a simple if to mark the column as check.
Macro used for extracting product code.
Public Function getProductCode(source As String) As String
Dim rExp As Object, allMatches As Object, match As Object
Dim result As String: result = ""
Set rExp = CreateObject("vbscript.regexp")
With rExp
.Global = True
.MultiLine = False
.Pattern = "(?:^|\D)(\d{7,8})(?!\d)"
End With
Set allMatches = rExp.Execute(source)
For Each match In allMatches
result = result + match.SubMatches.Item(0)
Next
getProductCode = result
End Function
A new column 'Reference' was then created on which the macro was used passing the specific column and the extracted product code is stored here.
After this a function was used to find duplicate entries and sum up the total number of products sold. The formula I used is as follows:
=ROUND(SUMIFS([Total],[Reference],[#Reference]),2)=0
Finally I used a simple if to mark the column as checked if the previously generated result (in column status) is true.
=IF([#Column1]=TRUE, "Checked", "")
This is how I got it done.
There might be better way to do it. But if anyone else is facing the same problem this will help.
I'm trying to write the match and index functions as vba code but its not working due to several errors.
In excel, I have a table R5:AD33
I used to match functions to get my row and column number to input into my index function.
=MATCH(R35,Q5:Q33, 0)
=MATCH(R36, R3:AD3,0)
Then I use the index function to give me the cell value corresponding to the row and column number.
=INDEX(R5:AD33,S35,S36)
I tried to input this as code however it gives me 2 errors I cant solve to proceed debugging.
This line of code below gives me the "assignment to constant not permitted". I'm not sure where the constant is as x is a variable.
WorksheetFunction.Match("NPS", Sheets("sheet2").ListObjects("Table1"), 0) = x
There was also a user type not defined error but it didn't highlight a particular line of code.
Thanks.
As part of an access application, i retrieve data from sql server. I have a string field that contains ⅝ in one of the rows, and when i attempt to insert that value into an MsAccess recordset, i get an error
Multiple-step operation generated errors. Check each status value. Here is my code
sFieldValue = getValue() ' when i add a watch, the '⅝' is replaced by a ? e.g. "The result is ⅝" will be shown as "The result is ?"
Rs(sFieldName) = sFieldValue ' error is thrown
I then attempted to hard code the value in VBA
sFieldValue ="⅝"
And the moment i type '⅝' it automatically changes to a question mark
sFieldValue ="?"
I would like to know how i can support characters such as "⅝". The other fractions work just fine, e.g. '½'. I do not want to do any calculations, the fractions are part of a string that comes from a SQL Server, and the problem is, i get a runtime error when i try to add a string value that contains a fraction to a recordset in access.
from this page, it shows that some fractions are supported in utf-8
The problem was that the field type of Rs(sFieldName) was adVarChar. So to fix the problem, i used a adVariant field type in my recordset, and it now accepts the ⅝ vulgar character.
I am creating the recordset on the fly.
Edit: adVarWChar is more appropriate, see comment below
This is code from Excel 2010. All of the code resides within the workbook itself. Information is gathered using internal forms and the code is run.
I have code that retrieves data from a spreadsheet and populates an object with that data. The row number is dynamic as it is dependent on the form input. The column is by the header, not the column number. The following code works perfectly but for two anomalies:
cTank.RowForTankSpecs = rNum
cTank.MP = .Cells(rNum, Range("MP").Column).Value
cTank.Form = .Cells(rNum, Range("formName").Column).Value
cTank.TankProcess = .Cells(rNum, Range("Process").Column).Value
cTank.Location = .Cells(rNum, Range("Location").Column).Value
cTank.TankName = .Cells(rNum, Range("Tanks").Column).Value
cTank.tankID = .Cells(rNum, Range("TankID").Column).Value
First:
The cTank.TankName is retrieving information from a column named "Tanks". That column does not exist. The actual column header is "Tank". But, it is retrieving the correct information. If I change the name to what it really is (Tank), it does not work.
Second:
When the cTank.TankID line is executed, I get the following error on the Range("TankID"):
Runtime Error 1004: Method 'Range' of object '_Global' failed
This one has the appropriate header (column header), but it is not recognizing the range.
I have tried simple things such as changing the order of the code, but it doesn't help. As earlier stated, the other lines work. Later in the program, information is gathered in the same manner but using another worksheet from the same workbook, and none of them are working. I've double checked that strings are strings and integers are integers, etc. I've double checked the column headers match the range names. Nothing seems to jump out at me.
I would appreciate any input you may have on the situation.
Thanks in advance.
Steve
Ok. Being pretty sure my code was correct, I went to the spreadsheet itself. For some reason it was recognizing only certain columns and it was recognizing one of them incorrectly. So I started highlighting the columns that worked and also the columns that didn't. What I noticed was that on the columns that were being recognized, that column header was displayed where the cell location is normally displayed whereas on the columns that were not being recognized, the cell location (i.e. A1, A2, etc.) for the header was being displayed and not the header title itself. The incorrect label was showing up for one of them. As it turns out, the mislabeled column was one that I had used for a form dropdown menu. So, I checked the name manager, and the ones that were working were listed. So anyway, using the name manager, I added named ranges using the headers. Now, when I select the columns, the column header(named range) appears in that window and now, the code works.
Thanks guys for your input. I really appreciate it.
Two things you can do:
Do not use use Range, but as it seems you are using names, use Names("Yourname").Referstorange.
OR
Make sure your names are set up correctly using the Name Manager in Data Ribbon.