Hi, I've searched for a sollution but it doesn't work, or I'm not good at fixing it
Anyway, I have a bit of VBA code that at some point cycles through a method (or function, or sub) several times. In that method I have the following line of code:
I use this to find the first empty cell in column E after which several rows of data are copied from one sheet to the other (not shown in code here).
The number of rows are different with every cycle. It can be 7, or 26 or 15, etc.
It works fine for about the first three or four times it cycles through. After that I get the Error 1004 No cells found error, and NextFree is 0.
I've tried using On Error Resume Next and that does something, but it just starts pasting to row 1 and below with every following cylcle, when it should be pasting to row 70, or 65, or 81 or whatever the first empty row is.
Below is the full code. I hope someone can help.
Anyway, I have a bit of VBA code that at some point cycles through a method (or function, or sub) several times. In that method I have the following line of code:
VBA Code:
NextFree = Worksheets("Gebouw_eisen_nieuw").Range("E1:E" & Rows.Count).Cells.SpecialCells(xlCellTypeBlanks).Row
I use this to find the first empty cell in column E after which several rows of data are copied from one sheet to the other (not shown in code here).
The number of rows are different with every cycle. It can be 7, or 26 or 15, etc.
It works fine for about the first three or four times it cycles through. After that I get the Error 1004 No cells found error, and NextFree is 0.
I've tried using On Error Resume Next and that does something, but it just starts pasting to row 1 and below with every following cylcle, when it should be pasting to row 70, or 65, or 81 or whatever the first empty row is.
Below is the full code. I hope someone can help.
VBA Code:
Private Sub CommandButton1_Click()
kopie_relevante_eisen CheckBox1
kopie_relevante_eisen CheckBox2
kopie_relevante_eisen CheckBox3
kopie_relevante_eisen CheckBox4
kopie_relevante_eisen CheckBox5
kopie_relevante_eisen CheckBox6
kopie_relevante_eisen CheckBox7
Application.ScreenUpdating = True
UserForm4.Hide
End Sub
VBA Code:
Public Sub kopie_relevante_eisen(cb As MSForms.CheckBox)
Dim c As Range
Dim NextFree As Long
Dim t As String
If cb.Value = True And cb.Tag = 0 Then
t = cb.Caption
'This works for the first 3 or 4 cycles, probably depending on the total number of rows copied, after that Error 1004
NextFree = Worksheets("Gebouw_eisen_nieuw").Range("E1:E" & Rows.Count).Cells.SpecialCells(xlCellTypeBlanks).Row
For Each c In Worksheets("Eisen").Range("D2:D184")
If c.Value = t Then
With Worksheets("Gebouw_eisen_nieuw").Range("E" & NextFree)
.Value = c.Offset(0, -2).Value
.Offset(0, -1).Value = t
.Offset(0, 1).Value = c.Offset(0, 2).Value
.Offset(0, -2).Value = c.Offset(0, -1).Value
End With
NextFree = NextFree + 1
End If
Next c
End If
End Sub