Results 1 to 4 of 4

Thread: excel question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2003
    Location
    Earth, I think!!
    Posts
    249

    excel question

    I need your assistance on this: I got two sheets (sh1, sh2), in sh1 got three columns
    Name, Date, Productivity (with the data below)
    Andy - 1/1/99 - 0
    John - 10/12/00 - 200
    George - 2/2/00 - 50
    Nick – 3/3/01 – 0

    How can I load the sh2 with the Name and Productivity columns and the rows that not got the 0 value? E.g.
    Name, Productivity
    John - 10/12/00 - 200
    George - 2/2/00 – 50

    What I need function or macro?? Please I need your help.
    Thanks!!

  2. #2
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    May be a faster way usinga Filter, but this will work.

    VB Code:
    1. Sub CopyNonZeros()
    2.  
    3.     ' Set sheets.
    4.     Dim sh1 As Worksheet
    5.     Dim sh2 As Worksheet
    6.     Set sh1 = Sheets(1)
    7.     Set sh2 = Sheets(2)
    8.    
    9.     Dim i       As Integer
    10.     Dim intNew  As Integer
    11.  
    12.     ' Loop all rows.
    13.     For i = 2 To sh1.Cells.SpecialCells(xlCellTypeLastCell).Row
    14.        
    15.         ' If Column C is not zero copy to new sheet.
    16.         If sh1.Range("C" & i).Value <> 0 Then
    17.             intNew = intNew + 1
    18.             sh2.Range("A" & intNew & ":" & "C" & intNew).Value = _
    19.                 sh1.Range("A" & i & ":" & "C" & i).Value
    20.         End If
    21.    
    22.     Next i
    23.  
    24. End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2003
    Location
    Earth, I think!!
    Posts
    249
    I got error 13(type Type mismatch) on this line:

    If sh1.Range("C" & i).Value <> 0 Then

  4. #4
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    Then not all values in Column C are numbers. Maybe format your sheet so all values in that column are numbers. Maybe try this:

    VB Code:
    1. If Int(sh1.Range("C" & i).Value) <> 0 Then

    You have to futz around a bit to make sure everything is doing everything the way you need it done.

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