简体   繁体   English

根据工作表名称将单元格复制到其他工作表

[英]copy cells to different worksheet based on worksheet name

I have been looking around and i cant seem to find the same flavor of question that I have lets say I have a worksheet that has two columns of data one column I apply a filter too and then use that to create worksheets. 我一直在环顾四周,我似乎找不到同样的问题,我可以说我有一个工作表包含两列数据,一列我也应用了过滤器,然后使用它来创建工作表。 I want then to paste the values from the second column that to a matching worksheet 然后,我要将第二列中的值粘贴到匹配的工作表中

So if I had column a had values abccd 因此,如果我的列a的值为abccd

and column b had values name fluid id state county I want the code to look at name and paste it to the proper worksheet in this example it would be worksheet a for fluid it would be worksheet b and so on and so forth b列具有值名称fluid id state county我希望代码查看名称并将其粘贴到本示例中的正确工作表中,这将是流体的工作表a和工作表b,依此类推,依此类推

i am thinking its a for each formula and then loop it so 我在想它的每个公式,然后循环

Sub C2s()
Dim contr As Control
Dim RN As Range
Dim LR As Integer

LR = Sheet3.Range("A" & Rows.Count).End(xlUp).Row
RN = Sheet3.Range("B1:B" & LR)

For Each Cell In RN
    If 

    End If
Next

End Sub

** Edited to fix column range being allocated **编辑以修正分配的列范围

This is untested, but should give you the idea of how to loop and use the offset column to process your values. 这未经测试,但是应该让您了解如何循环并使用offset列处理值。 The SpecialCells(xlCellTypeVisible) means it will only process the filtered records in your selection SpecialCells(xlCellTypeVisible)意味着它将仅处理您选择的过滤记录

    Dim MyCell As Range, 
Dim MyRange As Range
Dim WorksheetToCopyTo as string 
Dim LR As Integer

LR = Sheet3.Range("A" & Rows.Count).End(xlUp).Row
Set MyRange = Sheet3.Range("A1:A" & LR)

For Each MyCell In MyRange.SpecialCells(xlCellTypeVisible)
    WorksheetToCopyTo = MyCell.offset(0,1)
    Select Case WorksheetToCopyTo
        Case "Fluid"
            <do something here>
        Case "County"
            <do something here>
    End Select
Next MyCell

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM