[英]Trying to create a new excel sheet which is a summary of another sheet of data with conditions
I have a large data sheet 40 columns x 10000 rows which I want to abridge in a new sheet ready for export to a csv file. 我有一个较大的数据表,其中包含40列x 10000行,我想在一个新的表中进行精简以准备导出到csv文件。
The main data sheets relevant headings are:- 主要数据表的相关标题为:-
List | 列表| Segment |
细分| Group |
集团| Unsubscribed |
退订| Email |
电邮| Surname |
姓| First Name |
名| Mobile Number
手机号码
The new sheet wants to populate columns: segment, group, email, surname, first name and mobile number if "List" is equal to a value (in this case "Motorbike Sales"), "Unsubscribed" is NOT equal to -1 and "email" is NOT blank. 如果“列表”等于值(在这种情况下为“摩托车销售”),“取消订阅”不等于-1,则新工作表要填充以下列:段,组,电子邮件,姓,名和手机号码。 “电子邮件”不能为空。
At first I tried vlookup but it appears that this only works if everything in the "List" column is a unique value. 最初,我尝试了vlookup,但似乎只有在“列表”列中的所有内容都是唯一值时,此方法才有效。 In my case their are many "Motorcycle Sales" records.
就我而言,他们有许多“摩托车销售”记录。
I also tried some sample VBA code which did populate the new sheet but it would take forever and often crashed excel. 我还尝试了一些示例VBA代码,该代码确实填充了新工作表,但这会花费很多时间,并且经常导致excel崩溃。 I also couldn't work out how to add the conditions I require.
我也无法解决如何添加所需的条件。
My sample code is below. 我的示例代码如下。 Could someone help please - I have already lost a day and a half looking at on-line examples, tutorials and books.
有人可以帮忙吗-我已经花了一天半的时间看在线示例,教程和书籍。 I feel like I am missing something simple as I would expect this kind of sorting would be regular practice.
我觉得我缺少一些简单的东西,因为我希望这种排序是常规做法。
Thanks in advance 提前致谢
Private Sub Workbook_Open()
Dim i, LastRow
LastRow = Sheets("THS Contact Database").Range("A" & Rows.Count).End(xlUp).Row
Sheets("Motorbike Sales").Range("A2:AR10000").ClearContents
For i = 2 To LastRow
If Sheets("THS Contact Database").Cells(i, "A").Value = "Motorbike Sales" Then
Sheets("THS Contact Database").Cells(i, "A").EntireRow.Copy Destination:=Sheets("Motorbike Sales").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
End Sub
Copy the entire sheet, filter on List
to select and delete all rows not Motorbike
, filter on Unsubscribed
to select and delete all -1
, filter on email
to select and delete all (Blank). 复制整个工作表,在“
List
上过滤以选择并删除所有非Motorbike
行,在“ Unsubscribed
上过滤以选择并删除所有-1
,在email
上过滤以选择并删除所有(空白)。
Then delete columns List
and Unsubscribed
. 然后删除列
List
和Unsubscribed
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.