我正在尝试创建一个代码:
输入页面如下所示。如果黄色框为空白,则跳过该步骤,如果没有,则复制并粘贴到另一个名为“数据”的页面
你们有机会帮忙吗?我的代码都错了(我是初学者):(
Sub UpliftDelta()
Dim ws As Worksheet, inputs As Worksheet, datatbl As Worksheet, ws1 As
Worksheet
Dim c As Integer, i As Integer, j As Integer
Dim Tariffname As String
Set ws = Sheets("General")
Set ws1 = Sheets("StateSegFuel")
Set inputs = Sheets("Inputs")
Set datatbl = Sheets("Data")
Set Lookup_Range = inputs.Range("P1:R57")
a = ws1.Cells(Rows.Count, 1).End(xlUp).Row 'bottom most with numbers
b = datatbl.Cells(Rows.Count, 1).End(xlUp).Row 'bottom most with numbers
MsgBox a
MsgBox b
i = 8 'row in interface
j = 3 'column in interface
r = 1 'row in data
c = 0 'column in data
For i = 8 To a
If ws1.Cells(i, j - 1).Value = "PeakPrice1" Or ws1.Cells(i, j - 1).Value = "OffPeakPrice1" Or ws1.Cells(i, j - 1).Value = "ShoulderPrice1" Or ws1.Cells(i, j - 1).Value = "PeakBlock1" Then
If ws1.Cells(i, j).Value <> "" Then
Tariffname = ws1.Cells(i, j - 1).Value 'grab tariff name
ws1.Range(Cells(i, j), Cells(i, j + 5)).Copy 'copy range of numbers
c = Application.WorksheetFunction.VLookup(Tariffname, Lookup_Range, 3, False) 'grab column number of tariff
If datatbl.Cells(r, 7).Value = ws1.Range("H5") Then
datatbl.Activate
datatbl.Cells(r, c).PasteSpecial xlPasteValues 'paste inputs on Data table
End If
End If
i = i + 1
ElseIf ws1.Cells(i, j - 1).Value = "ShoulderBlock1" Or ws1.Cells(i, j - 1).Value = "OffPeakBlock1" Then
If ws1.Cells(i, j).Value <> "" Then
Tariffname = ws1.Cells(i, j - 1).Value 'grab tariff name
ws1.Range(Cells(i, j), Cells(i, j + 4)).Copy 'copy range of numbers
c = Application.WorksheetFunction.VLookup(Tariffname, Lookup_Range, 3, False) 'grab column number of tariff
If datatbl.Cells(r, 7).Value = ws1.Range("H5") Then
datatbl.Activate
datatbl.Cells(r, c).PasteSpecial xlPasteValues 'paste inputs on Data table
End If
End If
i = i + 1
ElseIf ws1.Cells(i, j).Value <> "" Then
Tariffname = ws.Cells(i, j - 1).Value 'grab tariff name
ws1.Cells(i, j).Copy 'copy range of numbers
c = Application.WorksheetFunction.VLookup(Tariffname, Lookup_Range, 3, False) 'grab column number of tariff
If datatbl.Cells(r, 7).Value = ws1.Range("H5") Then
datatbl.Activate
datatbl.Cells(r, c).PasteSpecial xlPasteValues 'paste inputs on Data table
End If
i = i + 1
Loop
End If
r = r + 1
Loop
MsgBox "Saved"
End Sub