PDA

View Full Version : Autofill a resize range



Ramo964516
03-01-2016, 02:19 PM
i'm working on a macro, and i use `resize` to select a range. Wich range i use in `autofill`. the original adress of `strPlageNumSemaines` is `AB5`. I don't know why it's still has `AB5` address even after the resize. Here is my code:




Dim strDernierJourDuMois As String
Dim strPlageNumSemaines As String
count = 0


strPlageNumSemaines = Range(strDernierJourDuMois).Offset(0, 1).Address
strPlageNumSemaines = Range(strPlageNumSemaines).Resize(1, count)


If dbNbSemaines = 4 Then
count = 4
ElseIf dbNbSemaines = 5 Then
count = 5
End If

Range("E5:AE5").Find(dtDernierJourDuMois, Range("E5")).Offset(0, 1).Select
Selection.AutoFill Destination:=Range(strPlageNumSemaines),Type:=xlFillDefault

xld
03-02-2016, 06:17 AM
Try this


Dim strDernierJourDuMois As String
Dim strPlageNumSemaines As Range

Count = 0

Set strPlageNumSemaines = Range(strDernierJourDuMois).Offset(0, 1).Resize(1, Count)

If dbNbSemaines = 4 Then
Count = 4
ElseIf dbNbSemaines = 5 Then
Count = 5
End If

Range("E5:AE5").Find(dtDernierJourDuMois, Range("E5")).Offset(0, 1).Select
Selection.AutoFill Destination:=strPlageNumSemaines, Type:=xlFillDefault