VBA Code To Turn Last Number Of Cell In Superscript Format

raindrop
Lounger
Posts: 36
Joined: 04 Feb 2013, 06:22

VBA Code To Turn Last Number Of Cell In Superscript Format

Post by raindrop »

Hi !

I want vba code to turn last number in superscript format in column C and if possible a formula for if any value of column A after decimal >= 50 should turn in round up value.
Please have a look at picture attached.

Thanks & Regards
Raindrop
You do not have the required permissions to view the files attached to this post.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: VBA Code To Turn Last Number Of Cell In Superscript Form

Post by Rudi »

Hi Raindrop,

The formula you need for the second part of your question is this:
=IF(A1-INT(A1)>=0.5,ROUNDUP(A1,0),A1)
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: VBA Code To Turn Last Number Of Cell In Superscript Form

Post by Rudi »

The code you can use is this:

It will convert the last character in all the cells in your selection to a superscript.
Select the cells to process and run the macro/

Code: Select all

Sub SuperscriptChar()
Dim i As Long
For i = 1 To Selection.Cells.Count
    Selection.Cells(i).Characters(Start:=Selection.Cells(i).Characters.Count, _
        Length:=1).Font.Superscript = True
Next i
End Sub
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

raindrop
Lounger
Posts: 36
Joined: 04 Feb 2013, 06:22

Re: VBA Code To Turn Last Number Of Cell In Superscript Form

Post by raindrop »

Thank You Rudi Sir,
You made my work easy. Could you please modify code - on enabling macro when opening workbook superscript macro automatically work for column C of sheet2 so selection is not required for every time.

Thanks & Regards
Raindrop

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: VBA Code To Turn Last Number Of Cell In Superscript Form

Post by Rudi »

Here is the code...
Make sure you put it in the ThisWorkbook module.

Code: Select all

Private Sub Workbook_Open()
Dim i As Long, rRng As Range
    Set rRng = Worksheets(2).Range("C1", Worksheets(2).Range("C" & Rows.Count).End(xlUp).Cells)
    Application.ScreenUpdating = False
    For i = 1 To rRng.Count
        rRng.Cells(i).Characters(Start:=rRng.Cells(i).Characters.Count, _
                                 Length:=1).Font.Superscript = True
    Next i
    Application.ScreenUpdating = True
End Sub
2014-03-23_11h36_58.jpg
You do not have the required permissions to view the files attached to this post.
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

raindrop
Lounger
Posts: 36
Joined: 04 Feb 2013, 06:22

Re: VBA Code To Turn Last Number Of Cell In Superscript Form

Post by raindrop »

Thank You Rudy sir,
Your code and formula both works great !

Thanks & Regards
Raindrop

Becks
2StarLounger
Posts: 196
Joined: 31 Mar 2011, 03:41
Location: Perth, Western Australia

Re: VBA Code To Turn Last Number Of Cell In Superscript Form

Post by Becks »

If the last number is always a 3, then a non-VBA solution is to replace 3 with ³ (Alt 0179 - hold down Alt key and enter 0179 using keypad)

regards
Becks

raindrop
Lounger
Posts: 36
Joined: 04 Feb 2013, 06:22

Re: VBA Code To Turn Last Number Of Cell In Superscript Form

Post by raindrop »

Thank You Sir for another option.

Thanks & Regards
Raindrop