簡體   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

我有一個導出到工作表按鈕,但我無法正常工作。 我選擇要復制的正確單元格但不能將它們轉置到單元格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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM