Results 1 to 7 of 7

Thread: excel - copying between sheets in macro

Threaded View

  1. #1

    Thread Starter
    Addicted Member Lee_S's Avatar
    Join Date
    Dec 2000
    Location
    New Zealand
    Posts
    250

    Question excel - copying between sheets in macro

    I have a workbook of sheets that contain data and then also a reports sheet which i want to use to pull data from the other sheets and list it.

    So, the idea is to scan through column E in each sheet and where the cell is empty copy the entire row to the next line available on the reports sheet.

    This sorta works, but only when 'reports' isnt the active sheet, and then it lists all the other rows after the needed ones. This probably isnt the best way to do it, is there a better way so that it doesnt matter which sheet is active? I'd quite like to put this into a button macro on the reports sheet.

    Code so far:
    VB Code:
    1. Sub Show_Outstanding()
    2. Dim ws As Worksheet
    3. Dim rng As Range
    4. Dim lLastRow As Integer
    5. Dim lLastCol As Integer
    6. Dim x As Integer
    7.  
    8.     For Each ws In Worksheets
    9.         If ws.Name <> "Reports" Then
    10.             Set rng = Worksheets(ws.Name).Range("A1").SpecialCells(xlCellTypeLastCell)
    11.             lLastRow = rng.Row
    12.             lLastCol = rng.Column
    13.            
    14.             For x = 2 To lLastRow
    15.                 If Cells(x, "E") = "" Then
    16.          
    17.                 Worksheets("Reports").Rows(FindBottomRow("Reports", 1)).Value = Worksheets(ws.Name).Rows(x).Value
    18.          
    19.                 End If
    20.             Next x
    21.         End If
    22.     Next
    23. End Sub
    Last edited by Lee_S; Sep 29th, 2005 at 04:26 AM.
    Lee Saunders
    Win XP Professional : VB6 Enterprise / VB 2005 Express

    History admires the wise, but it elevates the brave.

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