简体   繁体   English

根据其他单元格中的值将行数据从一张纸复制到一张或多张纸

[英]copy row data from one sheet to one or more sheets based on values in other cells

I have a sheet with user details in columns A - C. Columns DH is distribution lists the users are subscribed too. 我在A到C列中有一张包含用户详细信息的工作表。DH列是用户也已订阅的通讯组列表。 (currently check box linked to cell to indicate which list(s) user is subscribed to) (当前复选框链接到单元格以指示用户已订阅的列表)

A user can be subscribed to more than on list. 一个用户可以订阅的比列表中的更多。

At the moment I can use filters which works ok to filter users for list x, copy the user info to another sheet, then next list filterd (used text for the list selection) This does cause some problems between some of the users of this sheet.(those that don't know how to use filters) 目前,我可以使用可以正常过滤列表x的用户的过滤器,将用户信息复制到另一个工作表,然后过滤下一个列表(用于列表选择的文本),这的确在该工作表的某些用户之间造成了一些问题((那些不知道如何使用过滤器的人)

I would like to create a new sheet for each list which gets populated automatically. 我想为每个自动创建的列表创建一个新表。 As a user is added/removed from a list, his details is automatically added/removed from the corresponding 'list sheet'. 当用户从列表中添加/删除时,他的详细信息会自动从相应的“列表”中添加/删除。

This way no one can complain about the filters At the same time they can then export the 'list sheet' they require to another xls doc or csv as required. 这样,没有人可以抱怨过滤器。同时,他们可以根据需要将所需的“列表”导出到另一xls doc或csv。

I have found various options on how to do this, but all of then had only one selection column. 我已经找到了有关如何执行此操作的各种选项,但是所有这些都只有一个选择列。 I thought I could alter some of the ranges etc etc in the sample code but all failed with the limited knowledge I have with VB. 我以为我可以更改示例代码中的某些范围等,但是由于对VB的了解有限而全部失败。

Any suggestions on how to do this? 有关如何执行此操作的任何建议? Thanks! 谢谢!

Please do not try and create two copies of your data. 请不要尝试创建数据的两个副本。 Keeping two versions of the same data in step is very, very difficult. 保持同一数据的两个版本非常非常困难。

I believe your best option is to create a macro with which your users can select the filter they require. 我相信您最好的选择是创建一个宏,您的用户可以使用该宏选择所需的过滤器。

You do not describe your data in much detail so I have imagined something like the following: 您没有详细描述数据,因此我想到了以下内容:

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           

Given the above layout, the following macro shows the sort of thing I would offer. 给定上面的布局,下面的宏显示了我将要提供的东西。

When the macro is executed, it displays an InputBox like this: 执行宏后,将显示如下所示的InputBox:

在此处输入图片说明

from which the user can select the filter required. 用户可以从中选择所需的过滤器。

I hope this gives you some ideas. 我希望这能给您一些想法。

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

A simple solution, hope this helps 一个简单的解决方案,希望对您有所帮助

Here's a simple solution I figured: 这是我想出的一个简单解决方案:

  1. Copy the top row with the heading from the main sheet to all the sheets 将标题所在的第一行从主工作表复制到所有工作表
  2. Paste this formula in field A2 of each sheet: ='MainSheet'!A2:I555 (number 555 can be increased as per requirement) 将此公式粘贴到每张纸的字段A2中:='MainSheet'!A2:I555(数字555可根据要求增加)
  3. Drag this first row-wise, then column-wise till the end 首先将此行拖动,然后按列拖动到最后
  4. In the top row with the heading, filter the data as per your requirement, for eg in the MainSheet, data can be filtered on any column on any value needed 在标题的第一行中,根据您的要求过滤数据,例如在MainSheet中,可以在任何需要的任何值的列上过滤数据
  5. Do this for all the sheets 对所有工作表执行此操作
  6. When you update the data in the MainSheet, just re-run the filter to refresh the data 当您更新MainSheet中的数据时,只需重新运行过滤器即可刷新数据

HTH, HTH,

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将合并后的单元格从其他工作表复制到摘要工作表中的一个单元格中 - Copy merged cells from other sheets into one cell in summary sheet Excel VBA根据条件从一张纸复制到另一张纸的特定单元格 - Excel VBA copy from one sheet to other sheets specific cells based on criteria 从数据条目(如工作表)复制值并将它们粘贴到单个工作表中,根据一个单元格中的某个值连续粘贴 - Copy values from a data entry like sheet and paste them into individual sheets, in a row based on a certain value in one cell 将值从多张纸复制到一张纸 - Copy values from multiple sheets to one sheet 如何根据特定的列值将数据从一张纸拉到另外 3 张纸? - How do you pull data from one sheet to 3 other sheets based on specific column values? 有没有办法将列值从一个工作表复制到另一个工作表作为基于第一个分组的行 - is there any way to copy column values from one sheet to another sheet as row based on sheet one grouping 将单元格中的单元格复制到多张Excel - VBA中 - copy cells from one sheet into multiple sheets Excel - VBA 如何将特定范围单元格从多张纸复制到一张纸? - How to copy specific range cells from multiple sheets to one sheet? 将多张纸(但不是全部纸)的值复制/粘贴到一张纸中 - Copy/paste values from multiple sheets, but not all sheets, into one sheet Excel:2张,使用另一张表中的值填充一张表中的匹配单元格 - Excel: 2 sheets, populate the matching cells from one sheet with the values from the other
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM