我有一个宏的子集我写作需要一些修改&来自所有天才的帮助。
Sheet" Regions!A6:R6包含从表中提取数据的公式。我希望" Regions!A6:R6复制为值,然后粘贴在" Temp!A1""
您是否可以帮助修改此代码以实现此最终目标?
Sub Testing()
' Gets Number of Row in Regions Sheet
Sheets("Regions").Activate
LR1 = Cells(Rows.Count, "A").End(xlUp).Row
'Creates a New Worksheet and copy's the data from regions, interst the copied data into the
'New Temp Sheet and then removes the duplicates to create your list of unique items to filter on
'Creating the New WorkSheet
Sheets.Add.Name = "Temp"
'Copy the data
Sheets("Regions").Activate
Range("A6:R" & LR1).Select
Selection.Copy
'Paste the data into Temp Sheet
Sheets("Temp").Activate
Range("A1").Select
ActiveSheet.Paste
答案 0 :(得分:1)
我不是天才,但我总是试图运用良好的编码实践。首先我要摆脱那些Select
和Activate
的东西,简化代码,然后我分配Value
而不是使用复制/粘贴,这将使你摆脱公式并仅复制值。
Sub Testing()
Sheets.Add.Name = "Temp"
With Sheets("Regions").Range("A6:R" & Sheets("Regions").Cells(Rows.Count, "A").End(xlUp).Row)
Sheets("Temp").Range("A1").Resize(.Rows.Count, .Columns.Count).value = .value
End With
End Sub
答案 1 :(得分:1)
使用此
Sub Testing()
'Creating the New WorkSheet
Sheets.Add.Name = "Temp"
'Copy the data
With Sheets("Regions")
With .Range("R6", .cells(.Rows.Count, "A").End(xlUp))
Sheets("Temp").Range("A1").Resize(.Rows.Count, .Columns.Count).Value = .Value
End With
End With
End Sub