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

#### nhnn1986

##### Board Regular
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

### 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``````

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

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``````

Replies
0
Views
65
Replies
8
Views
290
Replies
2
Views
183
Replies
0
Views
127
Replies
10
Views
272

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

### 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.

### Which adblocker are you using?

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

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