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.

CPU S/N
Serial NumberCompare B:A
PBP1FGPPBP1FCTNot Available
PBE460X
PBP1FGPPBP1FGP
PBP1EWH
PBE460XPBE460X
PBP1FMCPBP1EWHPBP1EWH
PBE462N
PBP1FMCPBP1FMC
PBP1FNW
PBP1FNWPBP1FNW
PBP1FBF
PBP1FBFPBP1FBF
PBP1EWZ
PBP1EWZPBP1EWZ
PBP1FGH
PBP1FGHPBP1FGH
PBE460NPBE460NPBE460N
PBP1FDD
PBE462W
PBE461C
PBP1FRA

<colgroup><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

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