Link to home
Start Free TrialLog in
Avatar of weldo
weldo

asked on

Macro to delete error rows while retaining/summing some deleted information

Hey,

I need a macro to delete some rows while retaining and/or summing some of the information contained within specific columns of these rows. I have attached some Sample Data. As a starting point, for column F (labelled “T/C”), this only concerns rows where the entry in column F is “C” rather than “T”. I have attached a screenshot of the data (Sample Data Screenshot 1), and I will refer to rows 67 to 72 in Sheet1 of the sample data file as an example.

The problem can be seen in column M, “TimeSLC”. Each row beneath row 67 exists as a result of a data collection error. As can be seen, the value for rows 68-72 in column M is 4, related to the 4 minute gap between the final time and the initial time in columns D and B, respectively.

Using the example provided (rows 67-72), the following is required:

• Take the initial date and initial time from row 67, and combine this with the final date and final time in row 72. Delete the date and time entries between these, thereby remaining with one row with the correct date and time.
• For column I, ChTime, sum each of the values into this new row.
• Use the initial value in DistSLC (column L), and ignore (i.e. delete) the blanks below.
• Use the initial value of TimeSLC (column M), and ignore (i.e. delete) any values below.
• Use the value for SOCB in the first entry and SOCA in the final entry, and input these values into the new row, with the intermediate entries deleted.
• Use the values for columns R, S, and T (Loc1, Loc2 and Clim, respectively; see the attached sample data) from the first row of each occurrence.

I have attached a second screenshot (Sample Data Screenshot 2) with the desired outcome specific to these rows 67-72 (it must be noted that column I, ChTime, which is now equal to 305, does not exactly match the new amount of time between the final and initial times in the row, but this is not of concern).

The macro should stop summing and/or deleting the subsequent rows once either the value of column M (TimeSLC) is sufficiently large, such as greater than 60, or once the value of column F switches from “C” to “T” (in that order of preference; the value in column M should be checked before checking if the value of column F changed).

It must be noted that the value in column M (TimeSLC) is not necessarily 4 – it can be another small value, within the range of 0-59. Also, the dataset contains approximately 55,000 rows.

The problem always concerns when there are 2 or more values of “C” in a row; however, when there are multiple values of C in a row there is not always an error at play. Referring to Column M, if the second value is 60 or greater, then the entry is valid. There are two additional sample datasets on Sheet2 and Sheet 3 as examples.

Thanks for any help in making the macro.
Sample-Data.xlsx
Sample-Data-Screenshot-1.jpg
Sample-Data-Screenshot-2.jpg
ASKER CERTIFIED SOLUTION
Avatar of ElrondCT
ElrondCT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of weldo
weldo

ASKER

Hi,

Thanks a million for your help and the additional information, I tested the macro on the Sample Data and it worked exactly as desired.

However, when I checked to see if it worked on the overall database I received the Overflow error, "Run time error '6'".

It appears the error is in line 9 of the code:
RowEnd = Range("A1").End(xlDown).Row

It seems like it has located the correct row (row 55,453) but the error persists. I'm just wondering if you know what the problem might be?

Thanks again for your help!
Try changing RowEnd, iLine, and StartLine from Integer to Long.
Avatar of weldo

ASKER

Yeah that worked perfectly, cheers again!