I need a macro to autofill till col A range, thank you.

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi!
i have recorded this macro to convert bytes to MB and GB.
My table changes in rows not in col.
Sometimes when there is more row it does not calculate the formula, suppose there is two more row,
My formula range is from D2:D12, so it does not calculate.
I want the macro to autofill the formula if there is a value in Col a, which means if A15 has a value
then my formula should reach there.
THanks everyone.
My current code below:

[code*]

Sub Macro1()
'
' Macro1 Macro
'
'
Range("D1").Select
ActiveCell.FormulaR1C1 = "Size MB"
Range("E1").Select
ActiveCell.FormulaR1C1 = "Size Gb"
Range("D2").Select
ActiveCell.FormulaR1C1 = "=RC[-2]/(1024*1024)"
Range("D2").Select
Selection.AutoFill Destination:=Range("D2:D12"), Type:=xlFillDefault
Range("D2:D12").Select
Range("E2").Select
ActiveCell.FormulaR1C1 = "=RC[-1]/1024"
Range("E2").Select
Selection.AutoFill Destination:=Range("E2:E12"), Type:=xlFillDefault
Range("E2:E12").Select
Range("A1").Select
End Sub
[code*]
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try

Code:
Sub Macro1()
'
' Macro1 Macro
'
'
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("D1:E1").Value = Array("Size MB", "Size Gb")
Range("D2:D" & LR).FormulaR1C1 = "=RC[-2]/(1024*1024)"
Range("E2:E" & LR).FormulaR1C1 = "=RC[-1]/1024"
End Sub
When using code tags as I showed you in another thread, don't include the *. I added that to stop my examples turning into code tags ;)
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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