vba to autofill the formula

PinakiB

New Member
Joined
Mar 25, 2017
Messages
15
Hi,
I am working on a project where I require a formula to be autofilled till the last row. I am facing one issue regarding the autofill. I have two columns (example Column A and B) where data exists and I am writing a formula on Column C (C2). In column A and B data are variable meaning if column A contains data upto A80 then column B contains data upto B50 and the data can be changed for both the columns (A60 and B90). In this scenario when I am writing my formula in C2 and autofilling it is taking upto B column data only and if my A column is having large data than B rest data are not being autofilled. My purpose is to autofill the C column data following the large most column (A or B). Please help me to get rid of this issue.

[TABLE="width: 302"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]CPU S/N
[/TD]
[TD]Serial Number[/TD]
[TD]Compare B:A[/TD]
[/TR]
[TR]
[TD]PBP1FGP[/TD]
[TD]PBP1FCT[/TD]
[TD]Not Available[/TD]
[/TR]
[TR]
[TD]PBE460X
[/TD]
[TD]PBP1FGP[/TD]
[TD]PBP1FGP[/TD]
[/TR]
[TR]
[TD]PBP1EWH
[/TD]
[TD]PBE460X[/TD]
[TD]PBE460X[/TD]
[/TR]
[TR]
[TD]PBP1FMC[/TD]
[TD]PBP1EWH[/TD]
[TD]PBP1EWH[/TD]
[/TR]
[TR]
[TD]PBE462N
[/TD]
[TD]PBP1FMC[/TD]
[TD]PBP1FMC[/TD]
[/TR]
[TR]
[TD]PBP1FNW
[/TD]
[TD]PBP1FNW[/TD]
[TD]PBP1FNW[/TD]
[/TR]
[TR]
[TD]PBP1FBF
[/TD]
[TD]PBP1FBF[/TD]
[TD]PBP1FBF[/TD]
[/TR]
[TR]
[TD]PBP1EWZ
[/TD]
[TD]PBP1EWZ[/TD]
[TD]PBP1EWZ[/TD]
[/TR]
[TR]
[TD]PBP1FGH
[/TD]
[TD]PBP1FGH[/TD]
[TD]PBP1FGH[/TD]
[/TR]
[TR]
[TD]PBE460N[/TD]
[TD]PBE460N[/TD]
[TD]PBE460N[/TD]
[/TR]
[TR]
[TD]PBP1FDD[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]PBE462W
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]PBE461C
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]PBP1FRA
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi PinakiB,

Use below code:-

Code:
Sub DILIPandey()
'fill down formula based on column A and B
a = Range("a" & Rows.Count).End(xlUp).Row
b = Range("b" & Rows.Count).End(xlUp).Row
    If a > b Then
        n = a
    Else
        n = b
    End If
Range("C2:c" & n).FillDown
End Sub


Regards,
DILIPandey
 
Upvote 0
Hi DILIPandey,

It worked like a miracle..Its awesome really awesome..Thank you so much for your kind help..Its just worked what I was trying to find out. Thank you once again..

Regards,
Pinaki
 
Upvote 0
It just worked like a miracle..Thank you so much DILIPandey for your code..I was trying to find out what exactly I received from you. Thank you so much Sir..
 
Upvote 0

Forum statistics

Threads
1,223,262
Messages
6,171,080
Members
452,377
Latest member
bradfordsam

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