copy formual

Trevor3007

Well-known Member
Joined
Jan 26, 2017
Messages
667
Office Version
  1. 365
Platform
  1. Windows
Hi,

I wanted to create a 'macro' to copy the formula =if(a6>0,a6,"") and =if(b6>0,b6,"").

using the record macro feature, produced the following:-

VBA Code:
ActiveCell.FormulaR1C1 = "=IF(R[-1]C>0,R[-1]C,"""""
    Range("A7").Select
    Selection.Copy
    Range("B7").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Range("A7:B7").Select
    Selection.Copy
    Range("A8:A200").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Range("A6").Select
End Sub[CODE=vba]
[/CODE]

after running the macro, & inserting data into a6 & b6, returned the following ( see fig 1)

1628720021745.png

as you can se, it should of copied the data from a6 & b6 to a200:b200


can anyone solve this for me?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Please explain exactly what you are trying to accomplish.

It appears:
you want cell A7 to have the formula of =if(a6>0,a6,"")
you want cell B7 to have the formula of =if(b6>0,b6,"")
Not sure what you want after that. Are you trying to copy those formulas down to row 200?

Can you explain further what exactly you are trying to do?
 
Upvote 0
Does this do what you want?
VBA Code:
Sub try()
Range("A7:B7").Formula = "=IF(A6>0,A6,"""")"
Range("A7:B200").FillDown
End Sub
 
Upvote 0
Solution
Dang it @JoeMo You always stealing my thunder :)

VBA Code:
Sub TestCopyDown()
'
    Range("A7").Formula = "=IF(A6>0,A6,"""")"
    Range("B7").Formula = "=IF(B6>0,B6,"""")"
'
    Range("A7:B7").AutoFill Destination:=Range("A7:B200"), Type:=xlFillDefault
End Sub
 
Upvote 0
Does this do what you want?
VBA Code:
Sub try()
Range("A7:B7").Formula = "=IF(A6>0,A6,"""")"
Range("A7:B200").FillDown
End Sub
thnak you...works a treat.

have a great rest of your day.

PS
Sorry for the late reply, just gotten chance to test/try ?
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,315
Members
449,081
Latest member
tanurai

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