mylove0mylife
New Member
- Joined
- May 25, 2012
- Messages
- 13
Good afternoon,
In a particular column I'm trying to find all the "N/A"s and replace it with a formula. Is there a way to do this that won't get me a mistmatch error?
The error is occurring starting at "Selection.Replace" and ending at "ReplaceFormat:=False".
Here is the formula without R1C1 references, with pipe delimited (that's what I work in)
The formula works appropriately, when I enter it manually or paste it manually, but I'm having issues with VBA replicating this step. Is it because the formula isn't a String? How could I tell it (if this method won't work) to go down until you find an "N/A" and place this formula there? There is a different number of rows each time this is ran, but it will always be column N with the formula.
Thank you for any help. I'm still new to VBA, so I appreciate any guidance.
In a particular column I'm trying to find all the "N/A"s and replace it with a formula. Is there a way to do this that won't get me a mistmatch error?
The error is occurring starting at "Selection.Replace" and ending at "ReplaceFormat:=False".
VBA Code:
Sub Step_3()
Range("M2").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 1).Select
Range(ActiveCell, ActiveCell.End(xlUp)).Select
Selection.Replace What:="#N/A", Replacement:="=IF(AND(R[-4]C[11]<>"""",R[-4]C[11]<>""Hospitalist""),VLOOKUP(R[-4]C[11],'[Campaign_Maps and Data Tables.xlsx]Data Dictionary'!$D:$E,2,0),IF(AND(R[-4]C[13]<>"""",R[-4]C[13]<>""Hospitalist""),VLOOKUP(R[-4]C[13],'[Campaign_Maps and Data Tables.xlsx]Data Dictionary'!$D:$E,2,0),IF(R[-4]C[12]<>"""",VLOOKUP(R[-4]C[12],'[Campaign_Maps and Data Tables.xlsx]Data Dictionary'!$D:$E,2,0),IF(R[-4]C[-1]<>"""",VLOOKUP(R[-4]C[-1],'[Campaign_Maps and Data Tables.xlsx]Data Dictionary'!$D:$E,2,0),""Unknown""))))", Lookat:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End Sub
Here is the formula without R1C1 references, with pipe delimited (that's what I work in)
VBA Code:
=IF(AND(Y34<>""|Y34<>"Hospitalist")|VLOOKUP(Y34|'[Campaign_Maps and Data Tables.xlsx]Data Dictionary'!$D:$E|2|0)|IF(AND(AA34<>""|AA34<>"Hospitalist")|VLOOKUP(AA34|'[Campaign_Maps and Data Tables.xlsx]Data Dictionary'!$D:$E|2|0)|IF(Z34<>""|VLOOKUP(Z34|'[Campaign_Maps and Data Tables.xlsx]Data Dictionary'!$D:$E|2|0)|IF(M34<>""|VLOOKUP(M34|'[Campaign_Maps and Data Tables.xlsx]Data Dictionary'!$D:$E|2|0)|"Unknown"))))
The formula works appropriately, when I enter it manually or paste it manually, but I'm having issues with VBA replicating this step. Is it because the formula isn't a String? How could I tell it (if this method won't work) to go down until you find an "N/A" and place this formula there? There is a different number of rows each time this is ran, but it will always be column N with the formula.
Thank you for any help. I'm still new to VBA, so I appreciate any guidance.