Results 1 to 2 of 2

i receive an error running a macro

Threaded View

  1. #1
    Registered User
    Join Date
    06-17-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2007
    Posts
    14

    i receive an error running a macro

    included in this xlsx excel
    this macro should copies rows based on a value in a column.
    error:
    Run-time error 424 object req.
    then debug option
    line sheet2.Cells(1, 1).CurrentRegion.ClearContents

    this is the macro
    Sub expandIt()
        Dim pasteRow As Long, pasteRow2 As Long
         
         'clear existing data
        Sheet2.Cells(1, 1).CurrentRegion.ClearContents
         
         'Copy header
        Sheet1.Activate
        Sheet1.Range(Cells(1, 1), Cells(1, 8)).Copy Destination:=Sheet2.Cells(1, 1)
         
         'Copy each row to the required number of cells
        For Each cl In Range(Sheet1.Cells(2, 8), Sheet1.Cells(2, 8).End(xlDown))
            Sheet1.Range(Cells(cl.Row, 1), Cells(cl.Row, 7)).Copy
            pasteRow = Sheet2.Cells(65536, 7).End(xlUp).Row + 1
             
            If Sheet1.Cells(cl.Row, 8) = 1 Then
                Sheet1.Range(Cells(cl.Row, 1), Cells(cl.Row, 7)).Copy Destination:=Sheet2.Cells(pasteRow, 1)
            Else
                pasteRow = Sheet2.Cells(65536, 7).End(xlUp).Row + 1
                pasteRow2 = pasteRow + Sheet1.Cells(cl.Row, 8) - 1
                Sheet1.Range(Cells(cl.Row, 1), Cells(cl.Row, 7)).Copy _
                Destination:=Sheet2.Range("$A$" & pasteRow & ":$A$" & pasteRow2)
            End If
        Next
         
         'Fill Qty with 1's
        Sheet2.Range("$H$2:$H$" & pasteRow2) = 1
         
    End Sub
    Thanks

    chris
    Attached Files Attached Files
    Last edited by Leith Ross; 06-17-2009 at 06:14 PM. Reason: Added Code Tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1