返回列表 上一主題 發帖

[發問] 錄製後迴圈設定及插入複製的儲存格是否可以不插入圖案

有無直接的指令?  不曉得耶

用插入後再把圖刪除的方法

Sub kill_Image(R_指定範圍 As Range)

R_x1 = R_指定範圍.Left
R_x2 = R_指定範圍.Left + R_指定範圍.Width
R_y1 = R_指定範圍.Top
R_y2 = R_指定範圍.Top + R_指定範圍.Height

For Each p In R_指定範圍.Parent.Pictures
    x1 = p.Left
    x2 = p.Left + p.Width
    y1 = p.Top
    y2 = p.Top + p.Height
   
    xx = x1 >= R_x1 And x1 <= R_x2 Or x2 >= R_x1 And x2 <= R_x2
    yy = y1 >= R_y1 And y1 <= R_y2 Or y2 >= R_y1 And x2 <= R_y2
  
    If xx And yy Then
       p.Delete
    End If
Next
End Sub

TOP

回復 4# jackson7015

因為  Excel  2000 沒法用 #3樓的方法

TOP

回復 4# jackson7015

大大這樣試試看吧

........
    With Rows("48:48").Resize(, Rng.Rows.Count)    'columns/rows
        .PasteSpecial Paste:=xlPasteValuesAndNumberFormats
    End With
Rows("48:48").PasteSpecial Paste:= 7
Rows("48:48").PasteSpecial Paste:= 13
Rows("48:48").PasteSpecial Paste:= .....  ' 逐次添加缺少的
Rows("48:48").PasteSpecial Paste:= .....  ' 逐次添加缺少的

參數自己 try
https://msdn.microsoft.com/en-us/library/bb241405%28v=office.12%29.aspx

TOP

回復 7# jackson7015

我知道你用 insert 是為了方便不用計算區塊大小
但 insert 好像沒有參數讓你選擇排除哪些

    Sub 新增數量()

    插入次數 = 5
   
    Set R_Copy = Rows("1:47")
    Set R_Insert = Rows("48:48")
        
    For w = 1 To 插入次數
    R_Copy.Select
    R_Copy.Copy
    R_Insert.Insert Shift:=xlDown
    Next
   
    Set R_Insert = R_Insert.Offset(-R_Copy.Rows.Count * 插入次數)
    Set R_Insert = R_Insert.Resize(R_Copy.Rows.Count * 插入次數)
    Call kill_Image(R_Insert)
End Sub


Sub kill_Image(ByVal R_指定範圍 As Range)


R_x1 = R_指定範圍.Left
R_x2 = R_指定範圍.Left + R_指定範圍.Width
R_y1 = R_指定範圍.Top
R_y2 = R_指定範圍.Top + R_指定範圍.Height

For Each p In R_指定範圍.Parent.Pictures
    x1 = p.Left
    x2 = p.Left + p.Width
    y1 = p.Top
    y2 = p.Top + p.Height
   
    xx = x1 >= R_x1 And x1 <= R_x2 Or x2 >= R_x1 And x2 <= R_x2
    yy = y1 >= R_y1 And y1 <= R_y2 Or y2 >= R_y1 And y2 <= R_y2
  
    If xx And yy Then
       p.Delete
    End If
Next
End Sub

TOP

方法2

Sub 新增數量_2()
    插入次數 = 5
        
    Set R_Copy = Rows("1:47")
    Set R_Insert = Rows("48:48")
   
    Application.CutCopyMode = False
    R_Insert.Resize(插入次數 * R_Copy.Rows.Count).Insert
    R_Copy.Select
    R_Copy.Copy
    Set R_Insert = R_Insert.Offset(-R_Copy.Rows.Count * 插入次數)
    For w = 1 To 插入次數
        R_Insert.PasteSpecial
        Set R_Insert = R_Insert.Offset(R_Copy.Rows.Count)
    Next
End Sub

TOP

方法2
假設 你的資料列在 1 ~ 77 都有資料
如果你在 48 列用  Paste  貼入 30列
那麼原先的 48 ~ 77 列資料都會被覆蓋掉

所以
先用 "插入空白列" 把 48 ~ 77 列的資料往後移動 ( 插入無法選擇不貼圖, 所以這裡只插入空白列 )
再用 PasteSpecial  把資料複製到 剛剛插入的空白列  ( PasteSpecial  可以選擇不貼圖 )

這樣結合就避開了  insert 會貼入圖片, PasteSpecial  會覆蓋掉舊有的資料區

TOP

        靜思自在 : 謊言像一朵盛開的鮮花,外表美麗,生命短暫。
返回列表 上一主題