Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace All Text in Workbook

Status
Not open for further replies.

jgoodman00

Programmer
Jan 23, 2001
1,510
I am using VBA to open an Excel Workbook. This workbook contains a number of worksheets created by a series of dts packages which export data from SQL Server.

The data coming from SQL Server has a lot of True/False columns. I need to convert the True/False entries to Yes/No respectively.

Here is the code I am trying:
Code:
'Open the excel file
Set objExcelDoc = objExcel.Workbooks.Open(strTarget)
Dim i As Integer
On Error Resume Next
With objExcel
    .Cells.Replace What:="FALSE", Replacement:="No", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    .Cells.Replace What:="TRUE", Replacement:="Yes", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
End With


It never works, always stating the search string could not be found...

Any suggestions?

James Goodman MCSE, MCDBA
 
Perhaps are the value 0 for False and -1 (or 1) for True ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
I believe that PHV is right and that you are searching for the text "True" and Excel is finding the value of the result of a True/False Boolean expression.

Try this: Before you do your search/replace, copy the range of True/False cells and paste them back in the same cells as values. (Highlight range; Edit > Copy; Edit > Pastespecial > Values > OK) Then run your code.

Good Luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top