Help me to Fill in Max, Min, Average by code VBA

nhnn1986

Board Regular
Joined
Oct 12, 2017
Messages
92
Hi all

I have sheets("data") with data from column E to last column. Now I want to have macro to do in each row i (with i from 4 to last row)
Ai.value = Max(Di:lastcolumn)
Bi.value = Min(Di:lastcolumn)
Ci.value = Average(Di:lastcolumn

Please help me to do that, thanks./.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try this:

Code:
Sub Macro8()
    lr = Range("E" & Rows.Count).End(xlUp).Row
    lc = Cells(4, Columns.Count).End(xlToLeft).Column
    With Range("A4:A" & lr)
        .FormulaR1C1 = "=MAX(RC5:RC" & lc & ")"
        .Value = .Value
    End With
    With Range("B4:B" & lr)
        .FormulaR1C1 = "=MIN(RC5:RC" & lc & ")"
        .Value = .Value
    End With
    With Range("C4:C" & lr)
        .FormulaR1C1 = "=AVERAGE(RC5:RC" & lc & ")"
        .Value = .Value
    End With
End Sub
 
Upvote 0
Code worked, many thanks @DanteAmor

I have a question that: Do you have any suggess about:
For i = 4 to lr
Range("Ai") = FormulaR1C1 "=MAX(RC5:RC" & lc & ")"
Range("Bi") = FormulaR1C1 "=MIN(RC5:RC" & lc & ")"
Range("Ci") = FormulaR1C1 "=Average(RC5:RC" & lc & ")"
next i
 
Upvote 0
For it to work, it must be like this

Code:
Sub Macro9()
    lr = Range("E" & Rows.Count).End(xlUp).Row
    lc = Cells(4, Columns.Count).End(xlToLeft).Column
    For i = 4 To lr
        Range("A" & i).FormulaR1C1 = "=MAX(RC5:RC" & lc & ")"
        Range("B" & i).FormulaR1C1 = "=MIN(RC5:RC" & lc & ")"
        Range("C" & i).FormulaR1C1 = "=Average(RC5:RC" & lc & ")"
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,528
Messages
6,055,928
Members
444,835
Latest member
Jonaskr

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