Sum in selected cell

leaper1981

New Member
Joined
Aug 16, 2019
Messages
27
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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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
[TABLE="width: 1085"]
<colgroup><col><col><col><col><col><col><col><col><col><col><col span="2"><col><col><col></colgroup><tbody>[TR]
[TD]Day[/TD]
[TD]Time[/TD]
[TD]Job no[/TD]
[TD]Hours[/TD]
[TD]Customer[/TD]
[TD]Cust Ord No[/TD]
[TD]Product Code / Title[/TD]
[TD]Quantity [/TD]
[TD]Rep/New [/TD]
[TD]Price/1000 [/TD]
[TD]Cutter No[/TD]
[TD]Style[/TD]
[TD]Cyl Size[/TD]
[TD]Blank Size[/TD]
[TD]No Up[/TD]
[/TR]
[TR]
[TD]Mon[/TD]
[TD]08.00am[/TD]
[TD]30298[/TD]
[TD]1.5[/TD]
[TD]CATPHA[/TD]
[TD]102120 EO[/TD]
[TD]288459 10 CAV BC (A11297)[/TD]
[TD]15000[/TD]
[TD]NEW[/TD]
[TD]£353.00[/TD]
[TD]F2341[/TD]
[TD]Unglued Wallet[/TD]
[TD]10[/TD]
[TD]161x214 [/TD]
[TD] 2x1[/TD]
[/TR]
[TR]
[TD]Mon[/TD]
[TD]09:30am[/TD]
[TD]30292[/TD]
[TD]1.5[/TD]
[TD]CATPHA[/TD]
[TD]101506 EO[/TD]
[TD]288262 3X BT (A11213)[/TD]
[TD]2000[/TD]
[TD]NEW[/TD]
[TD]£716.00[/TD]
[TD]F2338 [/TD]
[TD]RTE with Fitment[/TD]
[TD]16[/TD]
[TD]321.7x390.25[/TD]
[TD] 1x1[/TD]
[/TR]
</tbody>[/TABLE]


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,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

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