复制粘贴特殊VBA不起作用

时间:2016-06-16 14:42:33

标签: excel vba excel-vba

我正在尝试将特殊值和格式从多个工作簿复制粘贴到主电子表格中。源和目标中的列数相同,行数也不同。

我阅读了其他主题并尝试了多种方法(包括在目标文件中定义一个范围)但我仍然无法使粘贴特殊工作。以下是我的代码:

Sub mergefiles()

Dim folderpath As String
Dim filepath As String
Dim filename As String
Dim erow As Long


folderpath = "D:\Test\"
filepath = folderpath & "*.xls*"
filename = Dir(filepath)

Dim lastrow As Long, lastcolumn As Long

Do While filename <> ""

  Workbooks.Open (folderpath & filename)

  Worksheets("EmplOffers").ShowAllData

  lastrow = ActiveSheet.Cells(Rows.Count, 3).End(xlUp).Row
  lastcolumn = ActiveSheet.Cells(6, Columns.Count).End(xlToLeft).Column

  Range(Cells(6, 3), Cells(lastrow, lastcolumn)).Copy

  Application.DisplayAlerts = False

  ActiveWorkbook.Close

  erow = Worksheets("EmplOffers").Cells(Rows.Count, 3).End(xlUp).Offset(1,     0).Row

  Worksheets("EmplOffers").Range(Cells(erow, 3), Cells(erow, 20)).PasteSpecial=:xlPasteValuesAndNumberFormats

  filename = Dir

Loop

Application.DisplayAlerts = True

End Sub

非常感谢!

2 个答案:

答案 0 :(得分:0)

尝试调整粘贴调用:

Worksheets("EmplOffers").Range(Cells(erow, 3).Address).PasteSpecial Operation:=xlPasteValuesAndNumberFormats

答案 1 :(得分:0)

命名参数应位于:=
之前  更改

   public class BaseController : Controller
    {
        public JsonResult JsonPublic(object data)
        {
            return Json(data);
        }
    }


    public static class ControllerExtensions
    {
        public static JsonResult AjaxRedirect(this BaseController cntrl, string action, object routeValues)
        {
            cntrl.JsonPublic() // accessible
        }
    }

收件人:

Worksheets("EmplOffers").Range(Cells(erow, 3), Cells(erow, 20)).PasteSpecial=:xlPasteValuesAndNumberFormats