Sum in selected cell

leaper1981

New Member
Joined
Aug 16, 2019
Messages
26
Hi,

Just wondering if anyone could help. I want to create a Macro that does the following:

I want to select any cell I have a figure in (say A1 has the number 3 in) and when I run the macro it does a sum related to that number, ie: number in cell (3 in this example) +10%, divided by 2, + .5 = (and the cell now shows the result.

So basically I want it to do a sum related to the value in any given cell. I can work out how to do the sum but I dont know how you tell a Macro to do that in whichever cell you currently have selected.

Can anyone help please?
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi & welcome to MrExcel
How about
Code:
   With ActiveCell
      .Value = .Value * 1.1 / 2 + 0.5
   End With
 
Upvote 0
Put into sheet code:


Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, [A1:A10]) Is Nothing Then        'set range as You need
    Target.Value = ((Target.Value * 1.1) / 2) + 0.5
End If
End Sub
 
Upvote 0
Or this...

Code:
    Dim Results As String
    'Gets vaule from colume A.
    Results = Range("A" & ActiveCell.Row).Value
    Results = (Results + (Results * 0.1)) / 2 + 0.5
    
    'Post results in colume B.
    Range("B" & ActiveCell.Row).Value = Results
 
Upvote 0
Or this...

Code:
    Dim Results As String
    'Gets vaule from colume A.
    Results = Range("A" & ActiveCell.Row).Value
    Results = (Results + (Results * 0.1)) / 2 + 0.5
    
    'Post results in colume B.
    Range("B" & ActiveCell.Row).Value = Results

Hi Guys,

Thanks for all your suggestions & sorry for my lack of understanding. This last one did exactly what I needed except it put the value in the cell next to it rather than over writing the value in the cell its working from (if that makes sense) I want it to replace the number.
 
Upvote 0
This will put the result of the calculation in the active cell
Code:
Sub leaper1981()
   With ActiveCell
      .Value = .Value * 1.1 / 2 + 0.5
   End With
End Sub
 
Upvote 0
Change the letter B to A should fixed the issue.

Code:
Dim Results As String
    'Gets value from column A.
    Results = Range("A" & ActiveCell.Row).Value
    Results = (Results + (Results * 0.1)) / 2 + 0.5
    
    'Override column A with the new results.
    Range("A" & ActiveCell.Row).Value = Results
 
Upvote 0
@Trixterz
That assumes the activecell is in col A, which may not always be the case.
 
Upvote 0
DayTimeJob noHoursCustomerCust Ord NoProduct Code / TitleQuantity Rep/New Price/1000 Cutter NoStyleCyl SizeBlank SizeNo Up
Mon08.00am302981.5CATPHA102120 EO288459 10 CAV BC (A11297)15000NEW£353.00F2341Unglued Wallet10161x214 2x1
Mon09:30am302921.5CATPHA101506 EO288262 3X BT (A11213)2000NEW£716.00F2338 RTE with Fitment16321.7x390.25 1x1

<colgroup><col><col><col><col><col><col><col><col><col><col><col span="2"><col><col><col></colgroup><tbody>
</tbody>


Scrap my previous request (sorry)

Just realised its harder than I thought due to the sum I need to do, didnt bother asking this as I thought it might be too difficult. Might make it easier to understand what I'm trying though.
The above is straight from the exel sheet i use. What I have to do is the following.
The hours are estimated originally & could be say 3 (as apposed to the 1.5 you can see as this has now been altered) How I end up at 1.5 is as follows
(order qty + 10%) / number up / 7000 = (1.178571428571429) I have then rounded it up to 1.5 (wouldn't require it to do that if not possible)

The problem I see here is the 'number up' Basically 2x1 would mean the figure I need to apply is 2, 1x1 would be 1, 2x2 would be 4 etc. Pretty sure Exel isnt going to be able to do that but possibly there is a way of getting it to ask you to enter the number up figure while it does the rest.

Not sure how easy this is to understand, I'm sure you guys would know what to do in a second if you were here lol If there is any chance of doing any of this but I havent given you enough info please let me know and I'll try to explain better.

Thanks again
 
Upvote 0
Do you want to do this on the entire set, or just certain cells?
 
Upvote 0

Forum statistics

Threads
1,213,526
Messages
6,114,136
Members
448,551
Latest member
Sienna de Souza

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