• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Change to combobox change event

Hello everybody,
I have this code (works fine)

Code:
Sub dotchie()
Dim lRow, cRow As Long
lRow = Sheets("Blad1").Range("A50000").End(xlUp).Row


For j = lRow To 1 Step -1
   
  If Sheets("Blad1").Range("A" & j) = "rood" Then
  cRow = Sheets("Rood").Range("A50000").End(xlUp).Row
  Sheets("Blad1").Rows(j).Copy Destination:=Sheets("Rood").Range("A" & cRow + 1)
  Sheets("Blad1").Rows(j).Delete
  ElseIf Sheets("Blad1").Range("A" & j) = "blauw" Then
  cRow = Sheets("Blauw").Range("A50000").End(xlUp).Row
  Sheets("Blad1").Rows(j).Copy Destination:=Sheets("Blauw").Range("A" & cRow + 1)
  Sheets("Blad1").Rows(j).Delete
   
  ElseIf Sheets("Blad1").Range("A" & j) = "wit" Then
  cRow = Sheets("Wit").Range("A50000").End(xlUp).Row
  Sheets("Blad1").Rows(j).Copy Destination:=Sheets("Wit").Range("A" & cRow + 1)
  Sheets("Blad1").Rows(j).Delete
  End If
Next
End Sub
But i would like to change it in something like this

Code:
Private Sub ComboBox1_Change()
Dim lRow, cRow As Long
lRow = Sheets("Blad1").Range("A50000").End(xlUp).Row
For j = lRow To 1 Step -1
If Me.ComboBox1.Value = "rood" Then
  cRow = Sheets("Rood").Range("A50000").End(xlUp).Row
  Sheets("Blad1").Rows(j).Copy Destination:=Sheets("Rood").Range("A" & cRow + 1)
  Sheets("Blad1").Rows(j).Delete
 Else
If Me.ComboBox1.Value = "blauw" Then
  cRow = Sheets("Blauw").Range("A50000").End(xlUp).Row
  Sheets("Blad1").Rows(j).Copy Destination:=Sheets("Blauw").Range("A" & cRow + 1)
  Sheets("Blad1").Rows(j).Delete
  Else
  If Me.ComboBox1.Value = "wit" Then
  cRow = Sheets("Wit").Range("A50000").End(xlUp).Row
  Sheets("Blad1").Rows(j).Copy Destination:=Sheets("Wit").Range("A" & cRow + 1)
  Sheets("Blad1").Rows(j).Delete
   
  End If
  End If
  End If
Next

End Sub
Thank you in advance
 
Dim lRow, cRow As Long makes cRow a Long , but lRow is a variant data type
so use
Dim lRow as long, cRow As Long
or
Dim lRow as long
Dim cRow As Long

Whats wrong with the code you want ?
 
Hoi Hui,
Thank you for your reply, I will ad the example.(i found out how )
The meaning is that if the value in combobox 1 is rood then the rows in sheet 1 (blad1) that contains rood in colom A goes to sheet rood ,for blauw to sheet blauw and so on
Thank you for the help
 

Attachments

  • Kopie van Kleur test-1.xlsb
    23.6 KB · Views: 1
Back
Top