I would like to sync my address list with the number shown in the cell at the front sheet.
The situation looks as follows:
In the cell D41 I have the number of flats. Now, when I open the "Address list" sheet I want to have the first row instantly copied 40 times down (marked with red). I know, that it can be described as a loop, this is why I tried this code:
- Original source here:
Relocation of multiple images with ID changing
Private Sub AddressList()
Dim i As Long
Dim rg As Range, rg2 As Range
Dim ws1 As Worksheet, ws2 As Worksheet
Set ws1 = ThisWorkbook.Sheets("Frontsheet")
Set ws2 = ThisWorkbook.Sheets("Address list")
Set rg = ws1.Range("D15").Value
For i = 1 To rg
Set rg2 = ws2.Range("B2:R2")
With rg2.Offset(i - 1, 0)
.Top = .Top
.Left = .Left
End With
Next I
End Sub
Here I am getting an error 424: Object required
Another code, which I tried is:
Sub AddressList()
Dim i As Long
Dim LastrowE As Long
Dim rng As Range
Dim rg As Range, rg2 As Range
Dim ws1 As Worksheet, ws2 As Worksheet
Set ws1 = ThisWorkbook.Sheets("Frontsheet")
Set ws2 = ThisWorkbook.Sheets("Fibre drop release sheet")
Set rg = ws1.Range("D32")
Set rg2 = ws2.Range("A2:k2")
For i = 1 To rg
With rg2.offset(i - 1, 0)
rg2.Copy _
Destination:=ws2.Range("A3")
End With
Next I
End Sub
it works, but the row is copied only once. I want to have it copied 41 times as states in the Frontshet.D15 cell. How can I do this?