+ Reply to Thread
Results 1 to 13 of 13

VBA to copy over Nil Values to different Tab

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    VBA to copy over Nil Values to different Tab

    Hi,

    I have the attached data which i need to pull account data across all the tabs that have zero values and transfer all the data to the 'Nil Accounts' tab?

    Anyone have any ideas?
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to copy over Nil Values to different Tab

    Maybe:

    Sub kenaadams378()
    Dim rcell As Range
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
    If ws.Name <> "Nil Accounts" Then
        ws.Activate
            For Each rcell In ws.Range("E1:E" & ws.UsedRange.Rows.count + 1)
                If rcell.Value = 0 Then
                rcell.EntireRow.Copy Sheets("Nil Accounts").Range("A" & Rows.count).End(3)(2)
                End If
            Next rcell
    End If
    Next ws
    End Sub

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA to copy over Nil Values to different Tab

    Another option.
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to copy over Nil Values to different Tab

    Many thanks, would it be possible to add which tab the data came from in column A, i also realised the data on the UL tab was not in the correct fields.

    Please see amended file.
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to copy over Nil Values to different Tab

    Maybe:

    Sub kenaadams378()
    Dim rcell As Range
    Dim ws As Worksheet
    Application.ScreenUpdating = False
    For Each ws In ActiveWorkbook.Worksheets
    If ws.Name <> "Nil Accounts" And ws.Name <> "UL Data" Then
        ws.Activate
            For Each rcell In ws.Range("E1:E" & ws.UsedRange.Rows.count)
                If rcell.Value = 0 Then
                Sheets("Nil Accounts").Range("A" & Rows.count).End(3)(1) = ws.Name
                Sheets("Nil Accounts").Range("A" & Rows.count).End(3)(2) = ws.Name
                Range(rcell.Offset(, -4), rcell).Copy Sheets("Nil Accounts").Range("B" & Rows.count).End(3)(2)
                End If
            Next rcell
    End If
    Next ws
    Sheets("UL Data").Activate
            For Each rcell In Range("K1:K" & ActiveSheet.UsedRange.Rows.count)
                If rcell.Value = 0 Then
                Sheets("Nil Accounts").Range("A" & Rows.count).End(3)(1) = ActiveSheet.Name
                Sheets("Nil Accounts").Range("A" & Rows.count).End(3)(2) = ActiveSheet.Name
                Range(rcell.Offset(, -4), rcell).Copy Sheets("Nil Accounts").Range("B" & Rows.count).End(3)(2)
                End If
            Next rcell
    Sheets("Nil Accounts").Range("B1:F1").Delete
    Sheets("Nil Accounts").Range("A" & Rows.count).End(3)(1).Delete
    Application.ScreenUpdating = True
    End Sub

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA to copy over Nil Values to different Tab

    Ken,

    The code works as long as the sheets format remain unchanged, otherwise you may get out of range error.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to copy over Nil Values to different Tab

    Thanks again, i've had to change the structure of the model due to something been left out so all the data is now is a 'full list' tab, i then need to take out the nil values from this list and add them to the nil values tab.

    This is my code

    With Sheets("Full List")
            For Each rcell In ws.Range("C2:C" & ws.UsedRange.Rows.Count + 1)
                If rcell.Value = 0 Then
                rcell.EntireRow.Copy Sheets("Nil Accounts").Range("A" & Rows.Count).End(3)(2)
                End If
            Next rcell
    End With
    But it doesn't copy anything over
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to copy over Nil Values to different Tab

    Your sample doesn't have a Sheets("Full List") and you have to change ws.usedrange to activesheet.usedrange

    Sub kenaadams378()
    Dim rcell As Range
    Application.ScreenUpdating = False
    Sheets("Nil Accounts").Rows("1:1").Value = Sheets("Full Data").Rows("1:1").Value
    With Sheets("Full Data")
            For Each rcell In Range("C2:C" & ActiveSheet.UsedRange.Rows.count + 1)
                If rcell.Value = 0 Then
                rcell.EntireRow.Copy Sheets("Nil Accounts").Range("A" & Rows.count).End(3)(2)
                End If
            Next rcell
    End With
    Application.ScreenUpdating = True
    End Sub

  9. #9
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to copy over Nil Values to different Tab

    Thanks for this, it appears it only copies the top line and nothing else...

    Ignore this post - Issue sorted
    Last edited by kenadams378; 11-05-2013 at 06:39 AM.

  10. #10
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to copy over Nil Values to different Tab

    Apologies, using the same data above i've amended my code to the following;

    With Sheets("Full Data")
    lrow = .Range("A" & .Rows.Count).End(xlUp).Row
         For Each cel In .Range(.Cells(2, 3), .Cells(.Range("A1").End(xlDown).Row, 3))
             If cel.Value = 0 Then
             cel.EntireRow.Copy
             Worksheets("Nil Accounts").Range("A" & lrow).PasteSpecial xlValues
             End If
         Next cel
    End With
    But it just doesn't copy anything

  11. #11
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to copy over Nil Values to different Tab

    Post #8 worked when I retested it?

  12. #12
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to copy over Nil Values to different Tab

    Thanks, i have since taken the code in post 8 into a larger model (too much data to post here) and it only copies the top line?

  13. #13
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to copy over Nil Values to different Tab

    Thanks for your help i have now solved the issue

    Many thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 8
    Last Post: 07-08-2013, 06:03 AM
  2. Need help making a macro to copy range of values based on cell values.
    By zolton in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-23-2013, 08:58 AM
  3. modify macro to copy values instead of copy and worbook instead of worsheet
    By sbab in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-11-2013, 08:43 AM
  4. Replies: 0
    Last Post: 09-06-2012, 04:06 AM
  5. [SOLVED] Copy/Paste how to avoid the copy of formula cells w/o calc values
    By Dennis in forum Excel General
    Replies: 10
    Last Post: 03-02-2006, 06:50 PM

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