I am writing small code to automate some of my work. I am using Autofill
to fill range. Everything works ok as long as the range stays the same. When I change range it shows error 1004: This operation requires the merged cells to be identically sized.
One more thing to add, it shows only when range becomes bigger.
Here is part of my code, when range changes line below 'autofill first column
becomes yellow:
Dim WSL As Worksheet, WSB As Worksheet
Dim first_col As Long, second_col As Long
Dim first_r As Byte, first_c As Byte
Dim second_r As Byte, second_c As Byte
Dim LastCellRowNumber As Long
Dim LastCell As Range, ActiveWS As String
Application.ScreenUpdating = False
Set WSB = Worksheets("Barcodes") 'your worksheet name
Set WSL = Worksheets("List") 'your worksheet name
With WSL
Set LastCell = .Cells(.Rows.Count, "A").End(xlUp)
LastCellRowNumber = LastCell.Row
End With
ActiveWS = ActiveSheet.Name
first_col = Round(LastCellRowNumber / 2) + 1
second_col = LastCellRowNumber - first_col
first_r = 5 'position of "first column" row
first_c = 7 'position of "first column" column
second_r = 5 'position of "second column" row
second_c = 11 'position of "first column" column
j = 7
k = 8
l = 7
m = 8
'activate Barcodes sheet
WSB.Activate
'autofill first column
WSB.Range(Cells(first_r, first_c), Cells(first_r + 1, first_c)).AutoFill _
Destination:=Range(Cells(first_r, first_c), Cells((first_r + 1) + (first_col * 2) - 4, _
first_c)), Type:=xlFillDefault 'filling column G
WSB.Range(Cells(first_r, first_c + 1), Cells(first_r + 1, first_c + 2)).AutoFill _
Destination:=Range(Cells(first_r, first_c + 1), Cells(first_r + 1 + (first_col * 2) - 4, _
first_c + 2)), Type:=xlFillFormats 'filling with columns H:I
'autofill second column
WSB.Range(Cells(second_r, second_c), Cells(second_r + 1, second_c)).AutoFill _
Destination:=Range(Cells(second_r, second_c), Cells(second_r + 1 + (second_col * 2), _
second_c)), Type:=xlFillDefault 'filling column K
WSB.Range(Cells(second_r, second_c + 1), Cells(second_r + 1, second_c + 2)).AutoFill _
Destination:=Range(Cells(second_r, second_c + 1), Cells(second_r + 1 + (second_col * 2), _
second_c + 2)), Type:=xlFillFormats 'filling with columns L:M