Умножить диапазон на значение, вставив значения в другой лист и отменив изменение
У меня есть следующий код, он должен иметь
- значения ячеек K50: AO50 в каждом листе равны K73: AO73, умноженные на Opex (который является переменным).
- Вставьте его на новый лист, а затем
- Вернитесь к листу, с которого взяты значения, и отмените изменения для всех листов в рабочей книге, чтобы значения на каждом отдельном листе остались нетронутыми.
Код, который я написал первым, дает мне ошибку несоответствия типов, а также я не знаю, как отменить изменения в исходных рабочих листах.
Option Explicit
Sub FinalGO()
' Check if New Worksheet already exists.
On Error Resume Next
Set ws = .Worksheets(strName)
If Err Then ' Does NOT exist.
On Error GoTo 0
Else ' DOES exist.
GoTo AlreadyDoneToday
End If
' Reenable error handling.
On Error GoTo ErrorHandler
' Add a New Worksheet to the last position in This Workbook.
.Sheets.Add After:=.Sheets(.Sheets.Count)
' In the New Worksheet.
With .Sheets(.Sheets.Count)
' Rename New Worksheet. If you already have used this code today,
' this line will produce an error. Delete the sheet or...
.Name = strName
' Write to cell A1 in New Worksheet.
.Cells(1, 1).Value = "Project Name"
.Cells(1, 2).Value = "NPV"
.Cells(1, 3).Value = "Total Capex"
.Cells(1, 4).Value = "Augmentation Cost"
.Cells(1, 5).Value = "Metering Cost"
.Cells(1, 6).Value = "Total Opex"
.Cells(1, 7).Value = "Total Revenue"
' Reset Row (Cells) Counter , because 1st already contains a value.
i = 1
' Loop through worksheets of This Workbook (.Parent).
For Each ws In .Parent.Worksheets
' Check the Name of the Current Worksheet.
Select Case ws.Name
' Do Nothing.
Case "Prices", "Home Page", "Model Digaram", _
"Validation & Checks", "Model Start-->", _
"Input|Assumptions", "Cost Assumption", "Index", "Model Diagram"
Case Else
If ws.Range("I92").Value = "" Then
ws.Range("K50:KO50").Value = ws.Range("K73:AO73").Value * Opex
ws.Range("k49:AO49").Value = ws.Range("K72:AO72").Value * Opex
Else
ws.Range("K49:AO49").Value = ws.Range("K72:AO72").Value * Opex
End If
' Count Rows (Cells).
i = i + 1
' Write name of Current Worksheet to cell in current
' Row and first column of New Worksheet.
.Cells(i, 1).Value = ws.Name
If ws.Range("I106").Value = "" Then
.Cells(i, 2).Value = ws.Range("I108").Value
Else
.Cells(i, 2).Value = ws.Range("I106").Value
End If
.Cells(i, 3).Value = ws.Range("AQ39").Value
.Cells(i, 4).Value = ws.Range("AQ23").Value
.Cells(i, 5).Value = Cells(i, 3).Value - Cells(i, 4).Value
.Cells(i, 6).Value = ws.Range("AQ65").Value
.Cells(i, 7).Value = ws.Range("AQ95").Value
end sub