Copying Value next to the highest value in column A

kshitij_dch

Active Member
Joined
Apr 1, 2012
Messages
362
Office Version
  1. 365
  2. 2016
  3. 2007
Platform
  1. Windows
Hi ,

I was working on a sheet where i have some values in column A , in the last cell of column A is the SUM of the values.

I am looking for a code that will copy the sum of values next to the highest value in column A , for an example :


[TABLE="width: 128"]
<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl63, width: 64"]Amount[/TD]
[TD="class: xl63, width: 64"]Value[/TD]
[/TR]
[TR]
[TD="class: xl63"]1000[/TD]
[TD="class: xl63"] [/TD]
[/TR]
[TR]
[TD="class: xl63"]2000[/TD]
[TD="class: xl63"] [/TD]
[/TR]
[TR]
[TD="class: xl63"]15000[/TD]
[TD="class: xl63"]24000[/TD]
[/TR]
[TR]
[TD="class: xl63"]1000[/TD]
[TD="class: xl63"] [/TD]
[/TR]
[TR]
[TD="class: xl63"]2000[/TD]
[TD="class: xl63"] [/TD]
[/TR]
[TR]
[TD="class: xl63"]3000[/TD]
[TD="class: xl63"] [/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl63"] [/TD]
[/TR]
[TR]
[TD="class: xl63"]24000[/TD]
[TD="class: xl63"] [/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Is this what you mean? Formula in B2 is copied down to B7.

Excel Workbook
AB
1AmountValue
21000 
32000
41500024000
51000
62000
73000
8
924000
Highest
 
Upvote 0
Yes exactly i wanted , Thank you Peter , is it possible i can convert this into macro code ?
 
Upvote 0
Yes exactly i wanted , Thank you Peter , is it possible i can convert this into macro code ?

Is the total formula already at the bottom of the column?

If not, should the macro insert that formula/value too?
 
Upvote 0
In column B, do you want just the value(s) (ie number) inserted, or do you want formulas so that if the numbers in column A change, column B will automatically adjust?
 
Upvote 0
Try this:

Code:
Sub Largest_Value()
'Modified 3-4-18 12:15 AM EST
Dim ans As Long
Dim Lastrow As Long
Dim mysum As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
mysum = Range("A" & Lastrow).Value
ans = Application.WorksheetFunction.Max(Range("A1:A" & Lastrow - 1))
Dim SearchString As String
Dim SearchRange As Range
SearchString = ans
Set SearchRange = Range("A1:A" & Lastrow).Find(SearchString, LookIn:=xlValues, lookat:=xlWhole)
SearchRange.Offset(0, 1).Value = mysum
End Sub
 
Upvote 0
In column B, do you want just the value(s) (ie number) inserted, or do you want formulas so that if the numbers in column A change, column B will automatically adjust?
This covers both - refer to the comment in the code.
Note that this code ..
- allows for the case where the maximum value in column A occurs more than once (noting that your sample data had repeating values)
- also works if the numbers in column A are not necessarily all whole numbers.

Rich (BB code):
Sub MarkHighest()
  With Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row - 1)
    .FormulaR1C1 = "=if(RC[-1]=max(R2C[-1]:R" & .Row + .Rows.Count - 1 & "C[-1]),R" & .Row + .Rows.Count & "C[-1],"""")"
    .Value = .Value   '<- Remove this line if you want to retain the formulas in column B
  End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,989
Members
452,541
Latest member
haasro02

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