Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autofill issue

Status
Not open for further replies.

andy7172289

Technical User
Aug 16, 2016
19
GB
Hi People,

I am trying to auto fill (Drag down) a row of formula's on one tab to a specific row number which is located in Cell (O7) from sheet 'RR S&C'.

This is what I have so far, but an error keeps coming up on the highlighted text in yellow. Can anyone show me where I'm going wrong please?



Sub Variants()


Application.ScreenUpdating = False

'---------------------------------------------------

Sheets("RR S&C").Range("O7").Copy
Range("O8").Select
Range("O8").PasteSpecial xlPasteValues

Sheets("RR PL").Select
Range("L7").Copy
Range("L8").Select
Range("L8").PasteSpecial xlPasteValues

Sheets("Validation").Select
Range("M7").Copy
Range("M8").Select
Range("M8").PasteSpecial xlPasteValues

' ----------------------------------------------------

Sheets("RR S&C").Select
Range("O8").Select
Value = Range("O8")
[highlight #FCE94F] Range("A2").AutoFill Destination:=Range("A2:L" & MyValue), Type:=xlFillSeries[/highlight]


'----------------------------------------------------------------------------------

Application.ScreenUpdating = True

End Sub


Thanks in advance!
 
Hi,

Where have you assigned a value to MyValue?

BTW, you also have a variable named [highlight #FCE94F]Value[/highlight]. That's a NO NO!!! [highlight #FCE94F]Value[/highlight] is a reserve word!

Every VBA user ought to have this option checked...

Tools > Options > Eidtor -- Requite variable declaration

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Okay, I'm guessing that the ending row values is what you intended to assign to MyValue...
Code:
Sub Variants()
'[b]
    Dim MyValue
'[/b]
    Application.ScreenUpdating = False
    
    '---------------------------------------------------
    
    With Sheets("RR S&C")
        .Range("O7").Copy
        .Range("O8").PasteSpecial xlPasteValues
    End With
    
    With Sheets("RR PL")
        .Range("L7").Copy
        .Range("L8").PasteSpecial xlPasteValues
    End With
    
    With Sheets("Validation")
        .Range("M7").Copy
        .Range("M8").PasteSpecial xlPasteValues
    End With
    
    ' ----------------------------------------------------
    
    With Sheets("RR S&C")
    '[b]
        MyValue = .Range("O8")
    '[/b]
        .Range("A2").AutoFill _
            Destination:=.Range("A2:L" & MyValue), Type:=xlFillSeries
    End With
    
    '----------------------------------------------------------------------------------
    
    Application.ScreenUpdating = True
    
End Sub

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Skip,

Thanks for looking at this. There is an error with the final part: 'Destination:=.Range("A2:L" & MyValue), Type:=xlFillSeries'.

Perhaps I should write it so that it just does it column by column?

Regards!
 
Have you tested contents of MyValue or, better, string "A2:L" & MyValue ?

combo
 
Andy,
It is customary to click on [blue]Great Post[/blue] link in the post that was most helpful.
This way you say:"Thank you" to the person who helped you, but also that little star indicates to other people which post to pay attention to.

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top