Removing Carriage Returns In A Data Array - Need VBA Help

milwphil

Board Regular
Joined
Aug 1, 2010
Messages
120
Good afternoon!

I have this code which is used to Trim (or remove spaces from all the cells in a dataArray); however, I also want to remove any "Carriage Returns". Can anyone help me add this to my working code?

AS ALWAYS! IT'S GREATLY APPRECIATED!

Code:
dataArray = dataSheet.Range(dataSheet.Cells(1, 1), dataSheet.Cells(LastRow + 1, 34)).Value
For tmpRow = headerRow + 1 To LastRow
    For tmpCol = 2 To lastCol
        [B]dataArray(tmpRow, tmpCol) = Trim(dataArray(tmpRow, tmpCol))
[/B]    Next tmpCol
Next tmpRow
dataSheet.Range(dataSheet.Cells(1, 1), dataSheet.Cells(LastRow + 1, 34)).Value = dataArray
lookupArray = lookupSheet.Range("Rules").Value
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Code:
dataArray(tmpRow, tmpCol) = Replace(dataArray(tmpRow, tmpCol), vbCr, vbNullString) ' or maybe, more likely, vbLf
 
' or 

dataArray(tmpRow, tmpCol) = WorksheetFunction.Clean(dataArray(tmpRow, tmpCol))

BTW, the VBA Trim and worksheet TRIM function are different in their behavior.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,855
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top