![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Posts: 222
|
Hi there,
Hoping that someone can help me: I have a lot of data that i import into excel in csv format, which is untidy. I run the trim and proper functions on the cells. Is there a easy to write (or use) function that i could assign a button too, which would do this for me. Thanks Richard |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Denver, Colorado USA
Posts: 4,014
|
Hi Richard,
I don't know if this is exactly what you want, but here is a macro that will Trim and Proper the contents of all cells on the active worksheet: Sub TrimProper() ' Trims and uppercases the contents of all cells on the ' active worksheet Dim Cell As Range For Each Cell In ActiveSheet.UsedRange Cell.Value = UCase(Trim(Cell.Value)) Next Cell End Sub
__________________
Keep Excelling. Damon VBAexpert Excel Consulting (My other life: http://damonostrander.com ) |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Posts: 222
|
Thanks Damon,
How would i apply this to the selected range of cells. thanks again rich |
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Denver, Colorado USA
Posts: 4,014
|
Hi again Richard,
To apply this to the selected cells, the code should be: Sub TrimProper() ' Trims and uppercases the contents of all selected cells on the ' active worksheet Dim Cell As Range For Each Cell In Selection Cell.Value = UCase(Trim(Cell.Value)) Next Cell End Sub |
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Feb 2002
Posts: 222
|
HI
this was a long time ago, but i have lost some data! this puts the items as uppercase, not in sentence case - i have tried amending the code by changing ucase to proper but i get a compile error any ideas please? thanks rich |
|
|
|
|
|
#6 |
|
MrExcel MVP
Moderator Join Date: Jul 2002
Posts: 49,241
|
There is no Proper function in VBA, so you need to use the worksheet function, eg:
Cell.Value = WorksheetFunction.Proper(Trim(Cell.Value)) |
|
|
|
|
|
#7 |
|
MrExcel MVP
Moderator Join Date: Aug 2003
Location: Sydney, Australia
Posts: 11,061
|
Just went through the Help. There is no Proper function in VBA, so you have to use the Excel version:
Code:
Sub TrimProper() ' Trims and uppercases the contents of all selected cells on the ' active worksheet Dim Cell As Range For Each Cell In Selection Cell.Value = Application.Proper(Trim(Cell.Value)) Next Cell End Sub Denis |
|
|
|
|
|
#8 |
|
Board Regular
Join Date: Feb 2002
Posts: 222
|
great
many thanks! |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|