![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Apr 2002
Location: Trussville, AL
Posts: 134
|
Hello, appreciate any help,
I have an error log that prints out two rows of data seperated by a blank row for each error. The error log prints out each month. There may be several hundred errors, but all but a few have a value of zero and are irrelevant. The first row of each error has 7 cells of data. The second row has 8 cells of data. The 6th cell (column) on the second row is the value. If it does not equal zero then I'd like to see that error. Looking for some VBA code to take each valid error and write it to another worksheet. Ideally I will initiate the macro via a button or other trigger and have the valid errors print out on the page below. Will repeat periodically each month. No need to keep a record of prior valid errors. I have a macro that can open the comma delimited text file, format it, copy it and apply a formula to identify the columns with the valid errors, but I don't know how to write the 2 rows of data to the second worksheet. Thank for any help, Philip |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
|
If row 8 ( for example) has errorCode>0 do you want both Row 7 and Row 8 copied to second sheet or just Row 8 ?
__________________
<MARQUEE>...........Never be afraid to try something new. Remember, amateurs built the ark, professionals built the Titanic...............The easiest thing to find is fault, don't be easy !.. --Anonymous--...</marquee> |
|
|
|
|
|
#3 | |
|
Board Regular
Join Date: Apr 2002
Location: Trussville, AL
Posts: 134
|
Quote:
Philip |
|
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Apr 2002
Posts: 112
|
[/quote]
I would want both row 7 and row 8 ideally. Philip [/quote] The code below only takes the 2 rows, but only the first 8 cells. It does not copy the entire row. Sub test() ErrorLog = ActiveSheet.Name LastRow = Cells(65536, 1).End(xlUp).Row Col_A = 1 Col_F = 6 Col_H = 8 RowNum = 1 'Adjust for you start row ErrorLog = ActiveSheet.Name While RowNum < LastRow If Cells(RowNum + 1, Col_F).Value <> 0 Then Range(Cells(RowNum, Col_A), Cells(RowNum + 1, Col_H)).Select Selection.Copy Sheets("Sheet2").Select If (Cells(1, 1).Value) = "" Then Cells(1, 1).Select Else Cells(65536, 1).End(xlUp).Offset(2, 0).Select End If ActiveSheet.Paste Sheets(ErrorLog).Select End If RowNum = RowNum + 3 Wend End Sub Hope it works! |
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Apr 2002
Posts: 112
|
Oops! Forgot to mention you would need to mofify the sheet names.
|
|
|
|
|
|
#6 |
|
MrExcel MVP
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
|
One last question:
If Row 8 Col 6 has your error value what does Row7 col6 have ? In other words is it a number or text ? It would make the solution easier if C7 and C8 had different data types.
__________________
<MARQUEE>...........Never be afraid to try something new. Remember, amateurs built the ark, professionals built the Titanic...............The easiest thing to find is fault, don't be easy !.. --Anonymous--...</marquee> |
|
|
|
|
|
#7 | |
|
Board Regular
Join Date: Apr 2002
Location: Trussville, AL
Posts: 134
|
Quote:
Philip [ This Message was edited by: PDuPre' on 2002-05-13 13:11 ] |
|
|
|
|
|
|
#8 | |
|
Board Regular
Join Date: Apr 2002
Location: Trussville, AL
Posts: 134
|
Quote:
Nimrod, if you have a different way to do this, I'd love to see it. Trying to learn as much as I can. Thanks! Philip |
|
|
|
|
|
|
#9 |
|
Board Regular
Join Date: Apr 2002
Location: Trussville, AL
Posts: 134
|
It works. Took me a bit to get it setup, but it copied over everything I wanted and nothing I didn't.
Thanks! Philip |
|
|
|
|
|
#10 |
|
MrExcel MVP
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
|
Oh well to late ... well here it is anyway.
Code:
Sub CopyErrorLog()
SourceSheet = "ErrorLog"
TargetSheet = "ErrorSummary"
TargRow = 1
EvalCol = 6
For RwCnt = 2 To 65536 Step 2
If Val(Sheets(SourceSheet).Cells(RwCnt, EvalCol).Value) > 0 Then ' copy and paste
Worksheets(SourceSheet).Range(RwCnt - 1 & ":" & RwCnt).Copy
Sheets("ErrorSummary").Range(TargRow & ":" & TargRow + 1).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
TargRow = TargRow + 2
End If
If Len(Trim(Sheets(SourceSheet).Cells(RwCnt, 1))) = 0 Then Exit Sub
Next
End Sub
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|