![](/img/trans.png)
[英]Copy merged cells from other sheets into one cell in summary sheet
[英]copy row data from one sheet to one or more sheets based on values in other cells
我在A到C列中有一张包含用户详细信息的工作表。DH列是用户也已订阅的通讯组列表。 (当前复选框链接到单元格以指示用户已订阅的列表)
一个用户可以订阅的比列表中的更多。
目前,我可以使用可以正常过滤列表x的用户的过滤器,将用户信息复制到另一个工作表,然后过滤下一个列表(用于列表选择的文本),这的确在该工作表的某些用户之间造成了一些问题((那些不知道如何使用过滤器的人)
我想为每个自动创建的列表创建一个新表。 当用户从列表中添加/删除时,他的详细信息会自动从相应的“列表”中添加/删除。
这样,没有人可以抱怨过滤器。同时,他们可以根据需要将所需的“列表”导出到另一xls doc或csv。
我已经找到了有关如何执行此操作的各种选项,但是所有这些都只有一个选择列。 我以为我可以更改示例代码中的某些范围等,但是由于对VB的了解有限而全部失败。
有关如何执行此操作的任何建议? 谢谢!
请不要尝试创建数据的两个副本。 保持同一数据的两个版本非常非常困难。
我相信您最好的选择是创建一个宏,您的用户可以使用该宏选择所需的过滤器。
您没有详细描述数据,因此我想到了以下内容:
Name Addr Tele List1 List2 List3 List4 List5
John London 1234 x
Jane Paris 2345 x
Kevin Stockholm 3456 x
Mary Brussels 4567 x
Nigel Dublin 5678 x
Abby Athens 6789 x x x
Brian Rome 7890 x
给定上面的布局,下面的宏显示了我将要提供的东西。
执行宏后,将显示如下所示的InputBox:
用户可以从中选择所需的过滤器。
我希望这能给您一些想法。
Option Explicit
Sub SelectFilter()
Dim ColNum() As Variant
Dim InxList As Long
Dim ListName() As Variant
Dim Prompt As String
Dim ReturnValue As Variant
' Load ListName with user-friendly names for the lists
ListName = Array("Name list 1", "Name list 2", "Name list 3", _
"Name list 4", "Name list 5")
' Load ColNum with the column number for each list. The entries in ColNum
' must be in the same sequence as the entries in ListName. Column "A" is
' column 1, column "B" is column 2 and so on.
ColNum = Array(4, 5, 6, 7, 8)
' Combine the user-friendly list names to create a menu
Prompt = ""
For InxList = 0 To UBound(ListName)
Prompt = Prompt & InxList + 1 & ". " & ListName(InxList) & vbLf
Next
Prompt = Prompt & "Please enter the number against the list you require." _
& vbLf & "Leave box empty to cancel selection."
' Loop until user cancels or enters a permitted value
Do While True
ReturnValue = InputBox(Prompt, "Select filter")
If VarType(ReturnValue) = vbBoolean Then
If Not ReturnValue Then
' The documentation for InputBox claims it returns False if
' the user clicks Cancel. In my experience it return a
' null string but check to be on the safe side.
Exit Sub
Else
' True is not a documented return value from InputBox.
' This code should never be executed but if something
' goes wrong there is a message for the user.
Call MsgBox("Please report there has been a InputBox " & _
"error type 1 to Chaka", vbCritical)
Exit Sub
End If
End If
If VarType(ReturnValue) <> vbString Then
' False or a string are the only documented return values
' This code should never be executed but if something
' goes wrong there is a message for the user.
Call MsgBox("Please report there has been a InputBox " & _
"error type 2 to Chaka", vbCritical)
Exit Sub
End If
If ReturnValue = "" Then
' User has clicked cancel or left the text box empty.
Exit Sub
End If
If IsNumeric(ReturnValue) Then
InxList = ReturnValue - 1
If InxList >= 0 And InxList <= UBound(ListName) Then
' Good selection
Exit Do
End If
End If
Loop
With Sheets("Sheet2")
If .AutoFilterMode Then
' AutoFilter is on. Cancel current selection before applying
' new one because criteria are additive.
.AutoFilterMode = False
End If
.Cells.AutoFilter Field:=ColNum(InxList), Criteria1:="x"
End With
End Sub
一个简单的解决方案,希望对您有所帮助
这是我想出的一个简单解决方案:
HTH,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.