I have a workbook that contains oil production information for oil wells. Each well has its own worksheet.I want to copy and paste the cumulative oil and gas production from each well into a preformated worksheet at the end of the workbook so i can get a list of the cumulative oil production.
The normal copy and paste vba isn't working for me because what I am trying to paste is a calculated value. Whenever I execute my current code, I get the #REF error.
I know this is not a unique question and that it has been asked before on here. I have looked at previous answers to this question though and tried to cannibalize the code but have failed. I know that I need to use the paste special function, but I cannot seem to figure out how to get this to work either.
I am copying the range AB3:AE3. The sheet name I am trying to copy and paste into is SmtProd. I want the values to be copied into the SmtProd sheet starting at row 2 (row 1 has the headers).
Below is my current copy and paste code
Range("AB3:AE3").Copy
Selection.Copy Sheets("SmtProd").Range("A" & Rows.Count).End(3)(2)
Any help would be appreciated
Thanks,
Josiah
Give this a try:
Sub MakeSummary()
Dim sh As Worksheet, N As Long
Dim i As Long, M As Long
N = Sheets.Count - 1
M = 2
For i = 1 To N
Sheets(i).Range("AB3:AE3").Copy
Sheets("SmtProd").Range("A" & M).PasteSpecial (xlValues)
Sheets("SmtProd").Range("A" & M).PasteSpecial (xlFormats)
M = M + 1
Next i
End Sub
Note the double-paste.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.