문제

I have a large data file that has some broken rows from the extraction process. I'm trying to clean it up in excel and am running into an issue with multiple row checking. I could nest a set amount of IF statements in my formula but that runs the risk of missing values. A Sample of the data looks like this (The strings are pasted into Column A):

'ID_Value','last_name','first_name','','dob','gender'comment
comment
comment
comment'
'ID_Value','last_name','first_name','','dob','gender'comment'
'ID_Value','last_name','first_name','','dob','gender'comment'
'ID_Value','last_name','first_name','','dob','gender'comment
comment
comment
comment
comment'

I need to roll the comment rows into the normal row preceding them. Currently I can identify all the rows and can make it work when there are two comment rows but going beyond that I am at a loss.

Formula in Column B:  =IF(LEFT(A1, 1) = "'", "IGNORE", "FLAG")
Formula in Column C:  =(IF(B2 = "FLAG", IF(B1 = "FLAG", "MOVE")))
Formula in Column D: =IF(B2 = "FLAG", IF(B1 = "FLAG", IF(C2 = "MOVE", CONCATENATE(A1, A2))))

Any recommendations are greatly appreciated.

도움이 되었습니까?

해결책

Here you go this should do it. Download the spreadsheet here.
Spreadsheet Example

Paste your data into Sheet 1 Cell A1 and click the run_filter button. Alternatively you can first run it with the dummy data that already present in Sheet1 and check to see that the results work as expected.

A couple of caveats.

  1. The macro will stop When it encounter a blank cell in Column A. This is how I determine that the macro should end.
  2. Comments should contain no more than 5 commas otherwise they'll be interpreted as real data.
  3. A space character is added to comments.
  4. The first row should not contain a comment.

A new worksheet called Filtered_Result will be created with the required result.


If you want to view the code click on the developer tab. If it's not present See here for How to add it tab Then Click the Macro Button. Macro Button Click the edit button on the macro combine_comments to see the code. edit button

Give it a try and let me know how it goes. Peter H

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top