我试图写下我的第一个宏。
这是我迄今为止所做的。它会打开一个文件,并将单元格中的公式复制而不是它们的值。你能帮我解决这个问题。
Sub CopyData()
Dim Wb1 As Workbook, wb2 As Workbook, file As String
file = Application.GetOpenFilename _
(Title:="Please choose a file to open", _
FileFilter:="Excel Files *.xls* (*.xls*),")
Range("A1").Value = file
Workbooks.Open Filename:=file
'copy from ThisWorkbook
Set Wb1 = ThisWorkbook
'To This
'Set wb2 = Workbooks(2)
Set wb2 = Workbooks.Open(file)
'Copy Data from Wb1.Sheet1 to Wb2.sheet1
wb2.Sheets("Questions").Range("C9:C200").Cells.Copy Wb1.Sheets(1).Range("D1:D200")
End Sub
答案 0 :(得分:0)
您可以尝试这样的事情......
wb2.Sheets("Questions").Range("C9:C200").Cells.Copy
Wb1.Sheets(1).Range("D1:D200").PasteSpecial xlPasteFormulasAndNumberFormats 'Will paste the formulas and number format
Wb1.Sheets(1).Range("D1:D200").PasteSpecial xlPasteFormats 'Will paste the formatting
答案 1 :(得分:0)
将复制行更改为以下内容:
Wb1.Sheets(1).Range("D1:D200").value = wb2.Sheets("Questions").Range("C9:C200").value