Problem with autofill function?

Mugalh01

New Member
Joined
Mar 23, 2018
Messages
15
Morning all,

Could you please help me out with my code - I'm simply trying to fill down from the cell with a formula (Rng2 in my code) but I'm getting error upon error.
Rng2.AutoFill Destination:=Range("E2:E14"), Type:=xlFillDefault - gives me an error; as does

Rng2.Select

Selection.AutoFill Destination:=Range("E2:E14"), Type:=xlFillDefault

My full code is as below - any help will be greatly appreciated.
Rich (BB code):
Sub Subpanel_tab()

Dim wsDestin As Worksheet
Dim Rng1 As Range
Dim Rng2 As Range
Dim Rng3 As Range

Set wsDestin = Sheets("Subpanel Coverage")

With wsDestin
Set Rng1 = wsDestin.Range("D2")
Set Rng2 = wsDestin.Range("E2")
Set Rng3 = wsDestin.Range("F2")

Rng1.FormulaR1C1 = _
        "=LEFT(RC[-3],SEARCH(""_"",RC[-3],SEARCH(""_"",RC[-3])+1)-1)"
Rng2.FormulaR1C1 = _
        "=IFERROR(MID(SUBSTITUTE(RC[-4],""_"",""^^"",2),FIND(""^^"",SUBSTITUTE(RC[-4],""_"",""^^"",2))+2,LEN(RC[-4])),""subpanel"")"
Rng2.AutoFill Destination:=Range("E2:E14"), Type:=xlFillDefault
Rng3.FormulaR1C1 = _
        "=IFERROR(LEFT(RC[-1],FIND(""_GENE"",RC[-1])-1),RC[-1])"
    Rng3.Select
    Selection.AutoFill Destination:=Range("F2:F14"), Type:=xlFillDefault
    Application.CutCopyMode = False

    End With

End Sub

Thank you.
 
Last edited by a moderator:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try
Code:
Sub Subpanel_tab()

Dim wsDestin As Worksheet
Dim Rng1 As Range
Dim Rng2 As Range
Dim Rng3 As Range

Set wsDestin = Sheets("Subpanel Coverage")

With wsDestin
   Set Rng1 = .Range("D2")
   Set Rng2 = .Range("E2")
   Set Rng3 = .Range("F2")
   
   Rng1.FormulaR1C1 = _
           "=LEFT(RC[-3],SEARCH(""_"",RC[-3],SEARCH(""_"",RC[-3])+1)-1)"
   Rng2.FormulaR1C1 = _
           "=IFERROR(MID(SUBSTITUTE(RC[-4],""_"",""^^"",2),FIND(""^^"",SUBSTITUTE(RC[-4],""_"",""^^"",2))+2,LEN(RC[-4])),""subpanel"")"
   Rng2.AutoFill Destination:=.Range("E2:E14"), Type:=xlFillDefault
   Rng3.FormulaR1C1 = _
           "=IFERROR(LEFT(RC[-1],FIND(""_GENE"",RC[-1])-1),RC[-1])"
   Rng3.AutoFill Destination:=.Range("F2:F14"), Type:=xlFillDefault
   Application.CutCopyMode = False

End With

End Sub
 
Upvote 0
Personally I see no need to use autofill at all as there appears to be no reason not to apply the formula directly to the ranges...

Code:
Sub Subpanel_tab()

    Set wsDestin = Sheets("Subpanel Coverage")

    With wsDestin

        .Range("D2").FormulaR1C1 = _
        "=LEFT(RC[-3],SEARCH(""_"",RC[-3],SEARCH(""_"",RC[-3])+1)-1)"
        
        .Range("E2:E14").FormulaR1C1 = _
        "=IFERROR(MID(SUBSTITUTE(RC[-4],""_"",""^^"",2),FIND(""^^"",SUBSTITUTE(RC[-4],""_"",""^^"",2))+2,LEN(RC[-4])),""subpanel"")"

        .Range("F2:F14").FormulaR1C1 = _
        "=IFERROR(LEFT(RC[-1],FIND(""_GENE"",RC[-1])-1),RC[-1])"


    End With

End Sub

I also don't see the need for the line below

Code:
Application.CutCopyMode = False
 
Upvote 0
Nice one Mark and Fluff,
Both codes work perfectly.

And you are right, i did not need the 'Application.CutCopyMode = False'

Thanks again
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,123
Members
452,381
Latest member
Nova88

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