![](/img/trans.png)
[英]Copy cells in column M that start with “xx” and paste them into another sheet
[英]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
我有一个导出到工作表按钮,但我无法正常工作。 我选择要复制的正确单元格但不能将它们转置到单元格A1下拉框中显示的选定工作表,然后我还需要将其粘贴到该特定工作表中的下一个可用行。 问题是我不能只在下拉框中的列表更改时列出VBA中的工作表。 我尝试了几种方法但没有成功。 如果有人可以帮助它会很棒
Sub Button2_Click()
Worksheets("Sheet1").Range("a2:x2").Copy
ActiveSheet.Paste Destination:=Worksheets("Sheet1!A1").Range("a:x")
End Sub
您需要更改工作表函数中的工作表名称。
这可能会奏效。
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
同样在粘贴范围内,您只需将第一个单元格区域设置为粘贴值。
要粘贴Transposed Values,请选中将Transpose属性设置为True的PasteSpecial函数。
这是我为此问题尝试过的一些代码,但似乎仍然没有用。
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
设置copySheet = Worksheets(“Data”)'On Error Resume Next'Fond Not(Application.Intersect(Range(“H2”),Target)Nothing)然后_
设置pasteSheet = Worksheets(ActiveSheet.Range(“H2”))
copySheet.Range(“G5:AA5”)。复制pasteSheet.Cells(Rows.Count,1).End(xlUp).Offset(1,0).PasteSpecial xlPasteValues Application.CutCopyMode = False Application.ScreenUpdating = True End Sub
'我找到了解决问题的另一种方法,将粘贴单元复制到某个工作表,然后在'人员工作表中填写表中的公式,以测试数据表上的列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
结束子
'员工表上的公式是 - = IF(Sheet3!A:A =“Column1”,Sheet3!$ B:$ B,“”)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.