Results 1 to 2 of 2

Thread: Copy problems

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    96

    Copy problems

    Hi

    I've run into a problem with copying using comboboxes as a value criteria, here's my code:

    VB Code:
    1. Private Sub CommandButton1_Click()
    2. Dim x As Long
    3. Dim i As Long
    4. Dim oControl As OLEObject
    5. Dim dSheet As Worksheet
    6. Dim sSheet As Worksheet
    7.  
    8. Set dSheet = ActiveWorkbook.Worksheets("Data")
    9. Set sSheet = ActiveWorkbook.Worksheets("Start")
    10.  
    11. dSheet.Copy after:=Sheets(1)
    12.  
    13. If Not ComboBox1.Value = "" Then
    14. For i = 2 To Sheet3.Cells(2, 1).End(xlDown).Row
    15.     If Not Sheet3.Cells(i, 1).Value = ComboBox1.Value Then
    16.         Sheet3.Rows(i).EntireRow.Delete
    17.     End If
    18. Next i
    19. If Not ComboBox2.Value = "" Then
    20. For i = 2 To Sheet3.Cells(2, 1).End(xlDown).Row
    21.     If Not Sheet3.Cells(i, 2).Value = ComboBox2.Value Then
    22.         Sheet3.Rows(i).EntireRow.Delete
    23.     End If
    24. Next i
    25. End If
    26. If Not ComboBox3.Value = "" Then
    27. For i = 2 To Sheet3.Cells(2, 1).End(xlDown).Row
    28.     If Not Sheet3.Cells(i, 3).Value = ComboBox3.Value Then
    29.         Sheet3.Rows(i).EntireRow.Delete
    30.     End If
    31. Next i
    32. End If
    33. If Not ComboBox4.Value = "" Then
    34. For i = 2 To Sheet3.Cells(2, 1).End(xlDown).Row
    35.     If Not Sheet3.Cells(i, 4).Value = ComboBox4.Value Then
    36.         Sheet3.Rows(i).EntireRow.Delete
    37.     End If
    38. Next i
    39. End If
    40. If Not ComboBox5.Value = "" Then
    41. For i = 2 To Sheet3.Cells(2, 1).End(xlDown).Row
    42.     If Not Sheet3.Cells(i, 5).Value = ComboBox5.Value Then
    43.         Sheet3.Rows(i).EntireRow.Delete
    44.     End If
    45. Next i
    46. End If
    47. For Each oControl In sSheet.OLEObjects
    48.         With oControl
    49.             If Left(.Name, 3) = "chk" Then
    50.             If Not .Object.Value = True Then
    51.                 For i = 6 To Sheet3.Cells(1, 1).End(xlToRight).Column
    52.                    If Sheet3.Cells(1, i).Value = .Object.Caption Then
    53.                        Sheet3.Columns(i).EntireColumn.Delete
    54.                    End If
    55.                 Next i
    56.             End If
    57.             End If
    58.         End With
    59.     Next oControl
    60. Else
    61.     Sheet3.Delete
    62. End If
    63.  
    64. End Sub

    So I'm starting by copying my data sheet and thereafter trying to delete the rows and columns which doesn't match my criterias. If nothing is selected then the copy should get deleted again.

    I can't find the error -I get an "object required" - but I can't see what's wrong, to me it looks pretty straight forward!

    Nicolaj

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    96

    Re: Copy problems

    Update:

    So I just tried running the debugger through the whole thing, following problems observed:

    1- I get an error (object missing), when I reach the sheet copy line dSheet.Copy after:=Sheets(1)

    2- When I bypass this error and do it manually my results doesn't match my criteria at all!

    Any ideas would be greatly appreciated, since I'm in a hurry!

    regards

    Nicolaj

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width