简体   繁体   English

我想复制一系列单元格并将它们粘贴到另一个工作表,具体取决于下拉选择并使用按钮激活

[英]I want to copy a range of cells and paste them to another sheet dependent on a drop down selection and activated using a button

I have an Export to sheet button but I can't get it working correctly. 我有一个导出到工作表按钮,但我无法正常工作。 I selects the correct cells to copy but can't then transpose them on to selected sheet that appears in the drop down box in cell A1, I then also need it to paste on the next available row in that specific sheet. 我选择要复制的正确单元格但不能将它们转置到单元格A1下拉框中显示的选定工作表,然后我还需要将其粘贴到该特定工作表中的下一个可用行。 The problem is that I can't just list the sheets in VBA as the list in the drop down box changes. 问题是我不能只在下拉框中的列表更改时列出VBA中的工作表。 I have tried several ways to with no success. 我尝试了几种方法但没有成功。 If someone could help it would be great 如果有人可以帮助它会很棒

Sub Button2_Click()

    Worksheets("Sheet1").Range("a2:x2").Copy
    ActiveSheet.Paste Destination:=Worksheets("Sheet1!A1").Range("a:x")

End Sub

you need to change the sheet name in your worksheet function. 您需要更改工作表函数中的工作表名称。

This might work. 这可能会奏效。

Sub Button2_Click()

'Copying the Data
Worksheets("Sheet1").Range("a2:x2").Copy

'Pasting the data
' What we were missing was to pass the name of the tab dynamically. Now this code will pick up the name that appears in the Cell A1.

ActiveSheet.Paste Destination:=Worksheets(Worksheets("Sheet1").Range("A1").value).Range("A1")

End Sub

Also in the paste range you only need to put the first cell range to paste values. 同样在粘贴范围内,您只需将第一个单元格区域设置为粘贴值。

To paste the Transposed Values check the function PasteSpecial with Transpose property set to True. 要粘贴Transposed Values,请选中将Transpose属性设置为True的PasteSpecial函数。

Here is some more code I have tried for the issue but still does not seem to work. 这是我为此问题尝试过的一些代码,但似乎仍然没有用。

Sub ExportButton1() ' ' ExportButton1 Macro ' Exports Data to staff sheet from drop down box ' ' Keyboard Shortcut: Ctrl+e ' ActiveWorkbook.Save End Sub Private Sub CommandButton1_Click(ByVal Target As Range) Application.ScreenUpdating = False Dim copySheet As Worksheet Dim pasteSheet As Worksheet Sub ExportButton1()''ExportButton1 Macro'从下拉框中将数据导出到员工表''键盘快捷键:Ctrl + e'ActiveWorkbook.Save End Sub Private Sub CommandButton1_Click(ByVal Target As Range)Application.ScreenUpdating = False Dim copySheet As Worksheet Dim pasteSheet As Worksheet

Set copySheet = Worksheets("Data") 'On Error Resume Next 'If Not (Application.Intersect(Range("H2"), Target) Is Nothing) Then _ 设置copySheet = Worksheets(“Data”)'On Error Resume Next'Fond Not(Application.Intersect(Range(“H2”),Target)Nothing)然后_

Set pasteSheet = Worksheets(ActiveSheet.Range("H2")) 设置pasteSheet = Worksheets(ActiveSheet.Range(“H2”))

copySheet.Range("G5:AA5").Copy pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues Application.CutCopyMode = False Application.ScreenUpdating = True End Sub copySheet.Range(“G5:AA5”)。复制pasteSheet.Cells(Rows.Count,1).End(xlUp).Offset(1,0).PasteSpecial xlPasteValues Application.CutCopyMode = False Application.ScreenUpdating = True End Sub

'I have found another way around the problem to copy paste cells to certain sheet then on 'staff sheet a formula in a table to tests column A value on data sheet for name and only 'transpose those rows '我找到了解决问题的另一种方法,将粘贴单元复制到某个工作表,然后在'人员工作表中填写表中的公式,以测试数据表上的列A值以获取名称并仅'转置这些行

Sub Macro1()
Range("A2:J2").Select
Selection.Copy
Sheets("Sheet3").Select
Range("A60000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
Sheets("Sheet1").Select

End Sub 结束子

'Formula on staff sheet is -=IF(Sheet3!A:A="Column1",Sheet3!$B:$B,"") '员工表上的公式是 - = IF(Sheet3!A:A =“Column1”,Sheet3!$ B:$ B,“”)

暂无
暂无

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

相关问题 复制M列中以“ xx”开头的单元格,然后将其粘贴到另一张表中 - Copy cells in column M that start with “xx” and paste them into another sheet 如何复制一系列公式值并将它们粘贴到另一个工作表中的特定范围? - How do I copy a range of formula values and paste them to a specific range in another sheet? 我想将单元格的范围从一张纸复制到下一张空白行的另一张纸 - I want to copy a range of cells from one sheet to another sheet in the next blank row 如何使用输入框复制单元格范围并将其粘贴到新创建的工作表中 - How to copy range of cells using inputbox and paste to newly created sheet 根据值复制一定范围的单元格,然后将其插入另一张纸上 - Copy a range of cells based on a value and insert them on another sheet 从一系列单元格中复制公式并将它们粘贴到循环 X 单元格中 - Copy formula's from a range of cells and paste them in a loop X cells down 从一张纸到另一张纸复制并粘贴一系列单元格,然后清除原始单元格中的数据 - Copy and paste a range of cells from one sheet to another then clear data from orignal cells 使用VBA并使用“偏移”将一系列单元格值复制并粘贴到另一张工作表中 - Copy and paste a range of cell values into another sheet with VBA and using Offset 如果另一个单元格中有值,则无法开发 vba 代码来复制某些单元格并粘贴它们。 - Trouble developing vba code to copy and certain cells and paste them dependent if there is a value in another cell 将范围从一张纸复制/粘贴到另一张纸 - Copy/Paste Range from one sheet to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM