Identify Trailing Chr(10) in a cell array

wsorensen

New Member
Joined
Nov 6, 2014
Messages
3
I need assistance in identifying and removing what I will call a lingering (2nd back to back) Carriage Return and remove it.

Scenario: On an excel spread sheet I have a multiline cell that includes rows of data separated by Char(10) "alt enter"
Each row in the multiline cell has a date "01/01/2020" a space, a dash and dollar amount $7,000.00 and a Char(10) to separate it form the next row of data
In some cases toward the end of the sequence of data and new line appears that only includes the hidden carriage return.
Following is what the cell contains and how it is formatted.

7/1/2016 - $13,867.88
7/1/2017 - $14,214.57
7/1/2018 - $14,569.94
7/1/2019 - $14,934.18
7/1/2020 - $15,307.54
7/1/2021 - $17,000.00
alt enter

I read this data into an array (see below) and then read it back to textboxes on a user form (see image Below)

Private Sub CompleteMultipage1_6() 'Rent Schedule
Application.ScreenUpdating = False
' Col Z or 26 is Rent Schedule
Dim Rentschedule() As String
Dim r As Integer
With ShMasterTracker
Rentschedule() = Split(ShMasterTracker.Range(Colrntsch & Rnum).value, Chr(10))

For i = LBound(Rentschedule) To UBound(Rentschedule) '- 1

Controls("TbRentStrtDteYr" & i) = Split(Rentschedule(i))(0)
Controls("TBRentyr" & i) = Split(Rentschedule(i))(2)
Next i

'read array back to user form textboxes in image below

For i = LBound(Rentschedule) To UBound(Rentschedule) '+ 1
' ColCurMontent Col AA or 27 is current monthly rent

If Year(Split(Rentschedule(i))(0)) = Year(Date) And Month(Split(Rentschedule(i))(0)) <= Month(Date) Then
TBCurBaseRent = Split(Rentschedule(i))(2)
' ShMasterTracker.Range(ColCurMonRnt & Rnum).value =
Exit For
End If

Next i
End With
Application.ScreenUpdating = True
End Sub

Text boxes on a user form that data is read back into
1606504486631.png


It works perfectly until it runs into the last row in the cell in which there is no data and just an Alt Enter (Char(10)) (Linger Carriage return).

As the userform is implemented I need to identify these lingering carriage returns and remove them, not just work around them.

Any assistance with this would be appreciated.

T
VBA Code:
hank you,
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Do you want to remove the last line feed from the cell, or just from the array?
 
Upvote 0
If you want to remove it from the cell try
VBA Code:
With ShMasterTracker
   With .Range(Colrntsch & Rnum)
      If Right(.Value, 1) = Chr(10) Then
         .Value = Left(.Value, Len(.Value) - 1)
      End If
      Rentschedule() = Split(.Value, Chr(10))
   End With
   For i = LBound(Rentschedule) To UBound(Rentschedule)
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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