Results 1 to 14 of 14

Code to find last Column keeps causing an error

Threaded View

dwhite30518 Code to find last Column... 06-01-2012, 03:34 PM
StevenM Re: Code to find last Column... 06-01-2012, 03:46 PM
dwhite30518 Re: Code to find last Column... 06-01-2012, 04:29 PM
StevenM Re: Code to find last Column... 06-01-2012, 04:45 PM
dwhite30518 Re: Code to find last Column... 06-01-2012, 04:48 PM
dwhite30518 Re: Code to find last Column... 06-01-2012, 05:13 PM
dwhite30518 Re: Code to find last Column... 06-01-2012, 05:11 PM
StevenM Re: Code to find last Column... 06-01-2012, 05:23 PM
dwhite30518 Re: Code to find last Column... 06-01-2012, 05:29 PM
dwhite30518 Re: Code to find last Column... 06-01-2012, 05:23 PM
tigeravatar Re: Code to find last Column... 06-01-2012, 06:04 PM
dwhite30518 Re: Code to find last Column... 06-01-2012, 06:10 PM
StevenM Re: Code to find last Column... 06-01-2012, 06:34 PM
dwhite30518 Re: Code to find last Column... 06-01-2012, 07:03 PM
  1. #1
    Forum Contributor
    Join Date
    05-13-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    378

    Question Code to find last Column keeps causing an error

    I have the following code...

    Sub SheetsToSummary()
    
        Dim LastRow As Long
        Dim ws As Worksheet
        Dim wsMaster As Worksheet
        
        Set wsMaster = Worksheets("Master Data Collection")
        
        For Each ws In ThisWorkbook.Worksheets
            With ws
                If .Name <> wsMaster.Name Then
                    If .Range("A1").Value = "Item" Then
                        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
                        .Range(.Cells(2, "A"), .Cells(LastRow, "D")).copy
                        With wsMaster
                            ' finds last used cell in column A and moves down a row
                            LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
                            .Cells(LastRow, "A").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
                                                                SkipBlanks:=False, Transpose:=False
                        End With
                    End If
                End If
            End With
        Next ws
        
    
    End Sub
    I would like the code to copy the last populated Column as well as the last populated row. It currently works fine with the last populated row but it only copies the first 4 columns and the number of columns varies on each worksheet. I have tried some different variation of writing for the last column but it keeps on causing errors. PLEASE HELP!!!!


    Thanks!
    Last edited by dwhite30518; 06-01-2012 at 03:38 PM. Reason: Forum Rules Violation

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