Find and Replace Carriage Return in Excel with VBA

Hi all,

I need to find all <CR> character (carriage return) because when I export a table from Access to Excel, the data contains "[]" that are carriage returns.

so i need to find these characters and replace with null

can i do this with vba?

many thanks

[361 byte] By [rexwrx] at [2007-12-24]
# 1
Hi, you could try something like this:

Dim objExcel As Excel.Application ' Excel object

Dim wbkTemp As Excel.Workbook ' Workbook

Dim wksTemp as Excel.Worksheet ' Worksheet

' Open record sets and objects

Set objExcel = CreateObject("Excel.Application")

Set wbkTemp = objExcel.Workbooks.Open(C:\Temp.xls)

Set wksTemp = wbkTemp.Worksheets(strQuery)

wksTemp.Activate

wksTemp.Range("A2:H100").Select

Selection.Replace What:=vbCrLf, Replacement:="", LookAt:=xlPart, _

SearchOrder:=xlByRows, MatchCase:=False

' Close record sets and objects

wbkTemp.Close True

Set wbkTemp = Nothing

objExcel.Quit

Set objExcel = Nothing

mungo at 2007-8-31 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...