Editing a cell with specific arguments

kashatxx

New Member
Joined
Nov 9, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello,

I searched and couldn't find what I needed.
Everything is either too broad or doesn't apply to my case.

I need a macro that will change the contents of a selected cell in the following manner:

given a cell that contains a price of $500 (if it matters, prices vary from 2 digits to 6 digits).

I need a macro that will add "=" at the start and "/2" at the end (always divide by 2).
The final result should look like this: =500/2.

manually it means the following set of actions:
selecting the cell
pressing F2 to start editing
pressing "Home"
pressing "="
pressing "End"
pressing "/2"
and finally pressing "Enter"

Is there a quick macro code that does that?

Thank you!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
For example: (works for range A1:A20)

VBA Code:
Sub jecc()
 Range("A1:A20").Name = "a"
 [a] = [if(a,a/2,"")]
End Sub

or

VBA Code:
Sub jec()
 For Each it In Range("A1:A20")
    If it Then it.Value = it.Value / 2
 Next
End Sub
 
Last edited:
Upvote 0
For example: (works for range A1:A20)

VBA Code:
Sub jecc()
 Range("A1:A20").Name = "a"
 [a] = [if(a,a/2,"")]
End Sub

or

VBA Code:
Sub jec()
 For Each it In Range("A1:A20")
    If it Then it.Value = it.Value / 2
 Next
End Sub

Thanks for the response @JEC !

Almost there, but I really need to add the "/2" in the cell.
I need it for tracking and visibility.

So say cell A2 shows $500
I need it to show "=500/2".
 
Upvote 0
*Can't find a way to edit my previous response, so posting a reply instead*

The cell on which this macro will be used changes all the time.
So it can't be a range or a specific cell.
It needs to be the active cell at the time.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,591
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top