Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA String sanitation

Tags:

string

excel

vba

I get data imported from an Oracle database and use Excel to create some reports from that. Recently one of our data entry folks has started beginning her entries with "+". Excel than evaluates that and adds = then displays the dreaded ?name# error. The error is error 2029.

I tried using

If IsError(C.Value) Then
    C.Value = Replace(C.Value, "=+", "", 1, -1, vbTextCompare)
End If

But that isn't getting me anywhere.

Any suggestions?

like image 299
CABecker Avatar asked Dec 02 '25 22:12

CABecker


1 Answers

Excel has it's own replace function:

ActiveSheet.Cells.Replace What:="=+", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
like image 116
DJ. Avatar answered Dec 05 '25 12:12

DJ.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!