This code snippet runs perfectly fine in Excel on Windows.
But on OSX, it's giving an error Named argument not found (Error 448).
With Sheets("Colors")
Set rangeFound = .Cells.find(What:=Resource, After:=.Cells(1, 1), LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
End With
The Mac does not support the SearchFormat argument. Just omit and the code will run.
Related
I am trying to make a VBA macro in excel which searches for a heading (succeeded at that), then selects the column of the heading (succeeded at that too) to finally do a replacement through the selected column (only partly succeeded in this).
I want to replace e.g SUM(C22:G22) with SUM(C22:INDIRECT(ADDRESS(ROW(); COLUMN()-1; 4))). It works just fine in excel when I select a column and then ctrl+H and find what :*) replace with :INDIRECT(ADDRESS(ROW(); COLUMN()-1; 4))).
Below is the code I tried that works:
Sub FindString_Search_Replace_Column()
Rows("1:1").Select
Selection.Find(What:="XTOTAL 2021", After:=ActiveCell, LookIn:= _
xlFormulas2, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.EntireColumn.Select
Selection.Replace What:=":*)", Replacement:=":A3)", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
End Sub
It does exactly what I want when it "just" needs to replace with e.g. A3. However, when the code replacement bit gets a bit longer, see below code, with what I actually need, it seems like it stops right after ActiveCell.EntireColumn.Select. It never actually changes anything.
Sub FindString_Search_Replace_Column()
Rows("1:1").Select
Selection.Find(What:="XTOTAL 2021", After:=ActiveCell, LookIn:= _
xlFormulas2, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.EntireColumn.Select
Selection.Replace What:=":*)", Replacement:=":INDIRECT(ADDRESS(ROW(); COLUMN()-1; 4)))", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
End Sub
I am thinking it is the inside ADDRESS bit it kind of chokes on but here my google skills cannot help me any further (no results suiting my problem).
Any ideas? :)
Try replacing the ; separators in your formula with , - when adding a formula in VBA typically you use "US-style" separator (unless assigning the formula via FormulaLocal).
Possibly that also applies to updating an existing formula.
I want to write the following Context using VBA.
When a specific word is selected in sheet 1, I want to find a specific word in sheet 2 and move it to that cell.
Selection.Copy
Sheets("Sheet2").Select
Cell.Find(What:=Apple, After:=ActiveCell, LookIn:=xlFormulas2, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, MatchByte:=False, SearchFormat:=False).Activate
End Sub
I want to put the word(Clipboard Paste?) to be copied instead of Apple, how can I do in this case ?
Don't use the Clipboard. The idea of the Clipboard is to exchange data between Applications. Just write the content of the selected cell into an intermediate variable and use that as search term.
And never access the result of a Find-command directly. If Find fails to find something, it will return Nothing, you will get nasty runtime errors when you execute Nothing.Activate. Instead, assign the result of the Find to another variable and check if it contains something:
Dim searchTerm as String
searchTerm = ActiveCell.Value
Sheets("Sheet2").Select
Dim hitRange as Range
Set hitRange = Cells.Find(What:=searchTerm, After:=ActiveCell, LookIn:=xlFormulas2, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, MatchByte:=False, SearchFormat:=False)
If Not hitRange Is Nothing Then hitRange.Activate
A remark: Usually it's a bad idea to use Select and Activate in your code. I just left it there because I assume that the reason for your Activate is to show the result to the user. If you plan to do something else with the result, don't use Activate. Instead, work with the Range variable (hitRange).
I've got a macro-enabled workbook that works just fine in Office365's version of Excel but earlier versions are breaking all over the place. If anyone could provide direction, I would appreciate it!
The current issue is with this bit below:
Range("1:1").Select
Selection.Find(What:="eventdate", After:=ActiveCell, LookIn:=xlFormulas2, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Select
Range(Selection.Offset(1, 0), Selection.Offset(1048570, 0).End(xlUp)).Select
Set rng = Selection
For Each eventdateCell In rng
eventdateCell.NumberFormat = "#"
eventdateCell.Value = WorksheetFunction.Text(eventdateCell.Value, "yyyy-mm-dd")
Next eventdateCell
I am trying to use VBA Find function to find a date from a column and then return the row number of the date.
This works:
Cells.Find(What:="1 Jul 13", After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
But, this doesn't work:
Cells.Find(What:=Range("E2"), After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Any idea? I want the user to input a date to "E2" and then run my code, so I would prefer to use the second way if possible.
Many thanks for your help.
Ben
If 1 Jul 13 actually appears in the cell, then use;
What:=Range("E2").Text
Say I have a range of data from A1:Y55 containg data like "123 UID"
I am looking for a unique substring (in this case, the UID) in that range, how do I do this?
You can do this with the following code.
On Error Resume Next
Range("A1:Y55").Find(What:="UID", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
The error statement will allow the program to continue if it does not find any matches.