|
-
Oct 6th, 2003, 03:54 PM
#1
Thread Starter
Addicted Member
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!!
-
Oct 6th, 2003, 10:25 PM
#2
Fanatic Member
May be a faster way usinga Filter, but this will work.
VB Code:
Sub CopyNonZeros()
' Set sheets.
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Set sh1 = Sheets(1)
Set sh2 = Sheets(2)
Dim i As Integer
Dim intNew As Integer
' Loop all rows.
For i = 2 To sh1.Cells.SpecialCells(xlCellTypeLastCell).Row
' If Column C is not zero copy to new sheet.
If sh1.Range("C" & i).Value <> 0 Then
intNew = intNew + 1
sh2.Range("A" & intNew & ":" & "C" & intNew).Value = _
sh1.Range("A" & i & ":" & "C" & i).Value
End If
Next i
End Sub
-
Oct 6th, 2003, 11:29 PM
#3
Thread Starter
Addicted Member
I got error 13(type Type mismatch) on this line:
If sh1.Range("C" & i).Value <> 0 Then
-
Oct 7th, 2003, 12:07 AM
#4
Fanatic Member
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:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|