Convert cells with percentage format to 'same' decimal in a column with mixed format - Excel Help & Excel Macro Help
SEARCH ENTIRE SITE LOADING..

OZGRID Excel Help & Excel Best Practices Forums

Information Helpful? Why Not Donate.

SPECIALS PAGE FOR BARGAINS | BUILD YOUR GOLF SWING | FREE CUSTOM FUNCTIONS ADD-IN


Download Active Data For Excel Demo


Go Back Excel Help & Excel Macro Help > HELP FORUMS > EXCEL HELP
HOME Register Forum Help Calendar Search For Today's Posts Mark Forums Read

Reply

Convert cells with percentage format to 'same' decimal in a column with mixed format

ANSWERS TO SIMILAR QUESTIONS
Convert Or Format Decimal To X Digits Without Decimal PointFormat All Percentage Cells To X Decimal PlacesConvert Date Format To Another FormatFind Time Format Cells And Convert To Dateconvert time in decimal format



Javascript DHTML Drop Down Menu Powered by dhtml-menu-builder.com

Create Excel dashboards quickly with Plug-N-Play reports.


 
Thread Tools Search this Thread
Old June 7th, 2006
Intelligent Converters
FREE DOWNLOADS
File/Password Recovery
magna magna is offline
I agreed to these rules
 
I'm a Spammer:
MS Office Version: 2000
Op System: Windows 2000
Assumed Experience: Average (Know Many Formulas)
Join Date: 10th May 2006
English is 1st Language:
Posts: 7 -- Threads: 2
Convert cells with percentage format to 'same' decimal in a column with mixed format

I have a column of cells with values - 0.2%, 0.32%, 0.22, 0.5 etc.
The cells with % symbol are in ' Percentage, 2 decimal' format while the plain numbers are in 'General' format i.e. column contains cells in either of these formats.
I need a macro where I can specify the column and it will select the cells with the % format, convert it to 'General' and multiply the result by 100 eg. 0.2% converted to 'General' becomes 0.002. When multiplied by 100, result is 0.2 i.e. is displayed without the % symbol.

Many thanks for your help.
Print [Post / Thread] Reply With Quote
Old June 7th, 2006
Intelligent Converters
FREE DOWNLOADS
File/Password Recovery
acw acw is offline
Long Term Member
 
I'm a Spammer:
MS Office Version: 2003
Op System: Windows XP
Assumed Experience: Expert (Know VBA Well and Use It & Excel Almos
Join Date: 6th May 2005
English is 1st Language:
Posts: 1,036 -- Threads: 1
Re: Convert cells with percentage format to 'same' decimal in a column with mixed format

Hi

How about
VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
Sub ddd() For Each ce In Range(Cells(1, ActiveCell.Column), Cells(Rows.Count, ActiveCell.Column).End(xlUp)) If ce.NumberFormat = "0.00%" Then ce.NumberFormat = general ce.Value = ce.Value * 100 End If Next ce End Sub

This runs based on the currently selected cell. No testing is done for multiple cell selections etc.

HTH

Tony
Print [Post / Thread] Reply With Quote
Old June 7th, 2006
Intelligent Converters
FREE DOWNLOADS
File/Password Recovery
magna magna is offline
I agreed to these rules
 
I'm a Spammer:
MS Office Version: 2000
Op System: Windows 2000
Assumed Experience: Average (Know Many Formulas)
Join Date: 10th May 2006
English is 1st Language:
Posts: 7 -- Threads: 2
Re: Convert cells with percentage format to 'same' decimal in a column with mixed format

Thanks acw!
I ran your code and it works till the last selected cell (I did a small test by selcting only 2 cells). Once that cell is formatted etc. it fails on the 'Next...' command with error 92 - For loop not initialized.
I am including my code below (with comments and queries). Appreciate if obvious errors can be corrected with helpful comments.

VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
Dim rCell As Range Dim rRange As Range Dim iChoice As Integer If Selection.Cells.Count = 1 Then MsgBox "Please select the range to convert", vbInformation Exit Sub End If On Error Resume Next ' I am working on Auto- filtered data. Hence I need my range to consist of 'visible cells in my selection. Set rRange = Selection.SpecialCells(xlCellTypeVisible) For Each rCell In rRange '(Cells(1, ActiveCell.Column), Cells(Rows.Count, ActiveCell.Column).End(xlUp)) ... Have modified your formula here to suit If rCell.NumberFormat = "0.00%" Then rCell.NumberFormat = "general" rCell.Value = rCell.Value * 100 End If Next rCell ' I now need to color rRange cells RED With Selection.Interior .ColorIndex = 3 .Pattern = xlSolid End With 'QUERY: I need to colour RED corresponding cells 4 columns to right. Is following code OK? Set rRange = rRange.Offset(, 4).SpecialCells(xlCellTypeVisible).Select With Selection.Interior .ColorIndex = 3 .Pattern = xlSolid End With iChoice = MsgBox("Wish to copy Fee Type & P Chg Criteria?", vbYesNo) If iChoice = vbYes Then MsgBox "Please select cells to copy" ' QUERY: I now need to manually select 2 adjacent cells from different columns after the msgbox and then copy them. I think something is missing ' between OK on msgbox to the next code line i.e how will the macro allow me to select and then remember the selection? Please help. Selection.Copy On Error Resume Next 'QUERY:Is this error capture step OK. Quite confused on which steps to include error lines? MsgBox "Please select destination range" 'QUERY: same problem as above. Set rRange = Selection.SpecialCells(xlCellTypeVisible) ActiveSheet.Paste Application.CutCopyMode = False Else Exit Sub 'This for vbNo choice. End If On Error Goto 0 'QUERY:Confused if this line is OK here? End Sub

Thanks again for your assistance.


Quote:
Originally Posted by acw
Hi

How about
VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
Sub ddd() For Each ce In Range(Cells(1, ActiveCell.Column), Cells(Rows.Count, ActiveCell.Column).End(xlUp)) If ce.NumberFormat = "0.00%" Then ce.NumberFormat = general ce.Value = ce.Value * 100 End If Next ce End Sub

This runs based on the currently selected cell. No testing is done for multiple cell selections etc.

HTH

Tony
Print [Post / Thread] Reply With Quote
Old June 8th, 2006
Intelligent Converters
FREE DOWNLOADS
File/Password Recovery
acw acw is offline
Long Term Member
 
I'm a Spammer:
MS Office Version: 2003
Op System: Windows XP
Assumed Experience: Expert (Know VBA Well and Use It & Excel Almos
Join Date: 6th May 2005
English is 1st Language:
Posts: 1,036 -- Threads: 1
Re: Convert cells with percentage format to 'same' decimal in a column with mixed format

Hi

Interesting - original code worked for me.

Can you give a small sample file showing what it is you are doing, and the expected results for given circumstances.


Tony
Print [Post / Thread] Reply With Quote
Old June 8th, 2006
Intelligent Converters
FREE DOWNLOADS
File/Password Recovery
magna magna is offline
I agreed to these rules
 
I'm a Spammer:
MS Office Version: 2000
Op System: Windows 2000
Assumed Experience: Average (Know Many Formulas)
Join Date: 10th May 2006
English is 1st Language:
Posts: 7 -- Threads: 2
Re: Convert cells with percentage format to 'same' decimal in a column with mixed format

Hi,
Sample file attached. Even though the sample file does not have it, presume I have filtered the data and the cells shown are just the 'visible' cells ie. row numbers are not continuous.

Col D has the mixed format. There can be blank cells in which case nothing needs to be done. Once formats fixed, the selected range in column D plus the corresponding cells in col E are to given a 'red' background colour. Please also see my code with the sequence of what I'm trying to achieve.

Many thanks ...
Attached Files. REMINDER! OzGrid accepts no responsibility for ANY adverse effects as a result from downloading attached files. ALWAYS run an up-to-date virus scan and disable macros.
File Type: xls Sample file-convert % to decimal.xls (14.5 KB, 49 views)
Print [Post / Thread] Reply With Quote
Old June 8th, 2006
Intelligent Converters
FREE DOWNLOADS
File/Password Recovery
acw acw is offline
Long Term Member
 
I'm a Spammer:
MS Office Version: 2003
Op System: Windows XP
Assumed Experience: Expert (Know VBA Well and Use It & Excel Almos
Join Date: 6th May 2005
English is 1st Language:
Posts: 1,036 -- Threads: 1
Re: Convert cells with percentage format to 'same' decimal in a column with mixed format

HI

Try the attached. Put your cursor on sheet1!D3, then run the macro ddd. Converts OK for me.



Tony
Attached Files. REMINDER! OzGrid accepts no responsibility for ANY adverse effects as a result from downloading attached files. ALWAYS run an up-to-date virus scan and disable macros.
File Type: xls magna.xls (26.5 KB, 42 views)
Print [Post / Thread] Reply With Quote
Old June 9th, 2006
Intelligent Converters
FREE DOWNLOADS
File/Password Recovery
magna magna is offline
I agreed to these rules
 
I'm a Spammer:
MS Office Version: 2000
Op System: Windows 2000
Assumed Experience: Average (Know Many Formulas)
Join Date: 10th May 2006
English is 1st Language:
Posts: 7 -- Threads: 2
Re: Convert cells with percentage format to 'same' decimal in a column with mixed format

Thanks acw - that worked.

Can you explain what your first line of code does? Specifically " Range(...,Cells(Rows.Count, ActiveCell.Column).End(xlUp))"

I think Cells(Rows.Count, ActiveCell.Column) determines the the row number by counting all the rows with data entry and ActiveCell.Column identifies the column number but why do we need End(xlUp)?

Thanks for the explanation...
Print [Post / Thread] Reply With Quote
Old June 9th, 2006
Intelligent Converters
FREE DOWNLOADS
File/Password Recovery
acw acw is offline
Long Term Member
 
I'm a Spammer:
MS Office Version: 2003
Op System: Windows XP
Assumed Experience: Expert (Know VBA Well and Use It & Excel Almos
Join Date: 6th May 2005
English is 1st Language:
Posts: 1,036 -- Threads: 1
Re: Convert cells with percentage format to 'same' decimal in a column with mixed format

Hi

Cells(rows.count,activecell.column) actually selects the last row in the spreadsheet (currently 65536) for the column you have selected. The xlup then does the equivalent of the ctrl up arrow which takes you to the last row with data in the currently selected column. If you come up from the bottom, you don't have the problem of blank cells if you try to go from the top down.

The code selects from row 1 in the current column, to the last row with data in the current column.


Tony
Print [Post / Thread] Reply With Quote
Reply Lifetime Upgrade To Ad Free Styles

   « PREVIOUS Avoiding Double Vlookup || Count Blank Cells in VBA NEXT »
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT +9. The time now is 22:08.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Ozgrid is Not Associated With Microsoft. Ozgrid Retains the Rights to ALL Posts and Threads