Excel Help
 

MegaSack DRAW - 6pm Christmas Eve - LIVE on our YouTube Channel

[Closed] Excel Help

12 Posts
10 Users
0 Reactions
79 Views
Posts: 6
Free Member
Topic starter
 

Need to remove a trailing semicolon from cells of varying lengths.

It will not always be present.

So would only need to be removed on the bottom of these two rows

Account group default (all); BI001816 D; XPTUAG557
Account group default (all); XXXY (XXXY123);

Any suggestions on the easiest way.

Thanks


 
Posted : 16/11/2016 3:26 pm
Posts: 23296
Free Member
 

data > text to columns. use semi-colon as a delimiter.


 
Posted : 16/11/2016 3:27 pm
Posts: 6
Free Member
Topic starter
 

Did think about that but number of semi colons in cell varies


 
Posted : 16/11/2016 3:29 pm
Posts: 77691
Free Member
 

Won't that explode if there's other semi-colons elsewhere in the cell?


 
Posted : 16/11/2016 3:29 pm
Posts: 0
Free Member
 

Export as CSV but use a character that doesn't appear in the cells as the separator, lets assume it's the comma.
Run sed "s/;,/,/" filename.csv > new_filename.csv
Import file back into Excel.


 
Posted : 16/11/2016 3:36 pm
Posts: 92
Full Member
 

Formula along the lines of...

=REPLACE(A1,LEN(A1),RIGHT(A1)=";","")


 
Posted : 16/11/2016 3:38 pm
Posts: 7184
Full Member
 

Define existing data as a table.

Create a new table in another sheet with the source as an SQL query.

Query is:

Select other fields ,
replace(old_table_element,";"," "), other fields from old_table

Edit: or just use the replace function in Excel (didn't know that existed).


 
Posted : 16/11/2016 3:41 pm
Posts: 722
Full Member
 

=IF(RIGHT(A1,1)=";",(LEFT(A1,LEN(A1)-1)),A1)


 
Posted : 16/11/2016 3:47 pm
Posts: 13594
Free Member
 

Hit Alt+F11

Click on Sheet1(Sheet1) and in RHS window type


Option Explicit

Public Sub CleanCells()

Dim Row As Integer
For Row = Sheet1.UsedRange.Rows(1).Row To Sheet1.UsedRange.Rows(1).Row + Sheet1.UsedRange.Rows.Count

Dim Cell As Range
For Each Cell In UsedRange.Rows(Row).Cells

If Right(Cells(Row, Cell.Column), 1) = ";" Then
Cells(Row, Cell.Column) = Left(Cells(Row, Cell.Column), Len(Cells(Row, Cell.Column)) - 1)
End If

Next Cell

Next Row

MsgBox ("All done")

End Sub

Hit CTRL+G

In the Immediate box at the bottom, type

call sheet1.CleanCells

It will remove any trailing semi-colons from all cells in Sheet1


 
Posted : 16/11/2016 4:05 pm
Posts: 6
Free Member
Topic starter
 

Formula along the lines of...

=REPLACE(A1,LEN(A1),RIGHT(A1)=";","")

Works but there appear to be random trailing spaces which throw it out.

Will use TRIM to tidy it up.

Thanks all


 
Posted : 16/11/2016 4:08 pm
Posts: 467
Free Member
 

Why not just use find and replace?


 
Posted : 16/11/2016 4:11 pm
Posts: 13594
Free Member
 

Why not just use find and replace?

Can't specify only trailing characters (that I know of). I just use VBA for everything.


 
Posted : 16/11/2016 4:13 pm
Posts: 6332
Free Member
 

what Doug said


 
Posted : 16/11/2016 4:15 pm