簡體   English   中英

VBA 填充目標單元格,從其他工作表獲取數據和參考

[英]VBA populate target cells getting data and reference from other sheet

我正在嘗試從循環迭代中復制一個范圍(范圍“M2:U11”根據單元格“A6”的值而變化)並將它們以精心安排的方式粘貼到單獨的工作表中。

所以我有一個新工作表(我們將其命名為 PDF 模板)。 我想粘貼相關的范圍(表格)並完全按照此圖像中顯示的格式/分發它們>>>>:

井然有序的范圍

我不知道這是否可能。 有答案嗎?

私有子 CommandButton1_Click()

'Declare our Variables
Dim rR As Range, rA6 As Range
Dim powerpointapp As Object
Dim mypresentation As Object
Dim myslide As Object
Dim myshape As Object
Dim i As Integer


'assigning range into variable
Set rR = ThisWorkbook.Worksheets("Sheet1").Range("M1:U11")
Set rA6 = ThisWorkbook.Worksheets("Sheet1").Range("A6")     '<<< Is A6 also on this sheet? Else correct sheet name

'If we have already opened powerpoint
Set powerpointapp = GetObject(class:="PowerPoint.Application")
                  
'If powerpoint is not opened
If powerpointapp Is Nothing Then Set powerpointapp = CreateObject(class:="PowerPoint.Application")

'To create a new presentation
Set mypresentation = powerpointapp.Presentations.Add

 
'Loop through all the values in "A6"
         'If Range("A6") = loop 1 To 100 Then Range("M1:U11").Select
         'Copy the Selection
         'Paste each iteration on a new slide on Powerpoint
         
For i = 1 To 300    'Loop A6 through all values from 1 to 300
    rA6 = i

    Set myslide = mypresentation.slides.Add(1, 11)
    'Copy the puzzle
    rR.Copy
    
    'to paste range
    myslide.Shapes.PasteSpecial DataType:=2
    Set myshape = myslide.Shapes(myslide.Shapes.Count)
    myshape.Left = 250
    myshape.Top = 150
    
Next i
    
powerpointapp.Visible = True
powerpointapp.Activate

'to clear the cutcopymode from clipboard
Application.CutCopyMode = False

結束子

如果你總是有 4 張紙,你可以只復制每張紙的范圍,告訴它把它粘貼到 PDF 紙上的什么地方。 然后復制包含所有四個工作表框的 PDF 工作表上的范圍,然后再將其粘貼到電子表格中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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