ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Copy cell value and delete white spaces at the end? (https://www.excelbanter.com/excel-discussion-misc-queries/265383-copy-cell-value-delete-white-spaces-end.html)

gombi

Copy cell value and delete white spaces at the end?
 
Hi experts!

I made a little excel worksheet to make my daily work a little easier. (Excel 97)

Now I have a simple problem!

I have a macro applied to a button and when I click on it a cell is copied in the clipboard because I need the data in a different application. The date in the cell is variable and changes depending what I did before I hit the copy button.

The cell is filled like that:


Range("K35").Select
ActiveCell.FormulaR1C1 = ActiveCell.Value & Cells(1, 1)

That works great but when I paste the content from the clipboard in another application (ex. notepad) there are a lot of white spaces after the cell content. I need to delete this white spaces before I paste the value in the other application.

I tried a few times with "Trim" but with no success. I don't know much about macro programming.

To copy the cell with the macro, I select the cell and then I use the copy funtion.

How can I delete this white spaces?

Range("F5").Select
Selection.Copy

Thank you so much!

Regards,
Michael

bala_vb

Quote:

Originally Posted by gombi (Post 958762)
Hi experts!

I made a little excel worksheet to make my daily work a little easier. (Excel 97)

Now I have a simple problem!

I have a macro applied to a button and when I click on it a cell is copied in the clipboard because I need the data in a different application. The date in the cell is variable and changes depending what I did before I hit the copy button.

The cell is filled like that:


Range("K35").Select
ActiveCell.FormulaR1C1 = ActiveCell.Value & Cells(1, 1)

That works great but when I paste the content from the clipboard in another application (ex. notepad) there are a lot of white spaces after the cell content. I need to delete this white spaces before I paste the value in the other application.

I tried a few times with "Trim" but with no success. I don't know much about macro programming.

To copy the cell with the macro, I select the cell and then I use the copy funtion.

How can I delete this white spaces?

Range("F5").Select
Selection.Copy

Thank you so much!

Regards,
Michael

use clean and trim function at a time to clean the data properly

dim a as variant
a=activeworkbook.sheets("sheet1").range("F5")
Application.WorksheetFunction.Clean(Trim(a))
a.copy

or

directly the trim the data in the excel spreadsheet and use vba code to copy and paste it.

all the best


All times are GMT +1. The time now is 02:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com