VBA Excel:计算

时间:2018-05-17 11:44:20

标签: excel vba excel-vba

Sub FallOrSpringsemester()

Dim enrollPeriod As String
Dim i As Integer
Dim LastRow As Integer
Dim w As Worksheet
Dim text As String


Set w = Sheets.Add(after:=Sheets(Sheets.Count))
w.Name = "oldest Students"

Worksheets("oldest Students").Cells(1, 1) = "Student_ID"
Worksheets("oldest Students").Cells(1, 2) = "Enroll_Date"
Worksheets("oldest Students").Cells(1, 3) = "Program_Type_Name"
Worksheets("oldest Students").Cells(1, 4) = "Enrollment_Period"

LastRow = Worksheets("Base").Range("D" & Rows.Count).End(xlUp).Row

    For i = 2 To LastRow

Worksheets("oldest students").Cells(i, 1) = Worksheets("Base").Cells(i, 12)

Worksheets("oldest students").Cells(i, 2) = Worksheets("Base").Cells(i, 4)

Worksheets("oldest students").Cells(i, 3) = Worksheets("Base").Cells(i, 11)

在这个编码之上,我的ofc有我的二维变量,也编码创建一个新的表。

我对这部分有困难,因为它不会进行计算并告诉我有错误 “13”:输入未命中匹配

    If enrollPeriod Mod 2 = 0 Then
    Worksheets("oldest Students").Cells(i, 2) = "Spring"
    enrollPeriod = enrollPeriod + 1
    Worksheets("oldest Students").Cells(i, 1) = 2018 - ((138 - enrollPeriod) / 2)

    Else

    Worksheets("oldest Students").Cells(i, 2) = "Fall"

    Worksheets("oldest Students").Cells(i, 1) = 2018 - ((138-enrollPeriod) / 2)

   End if  
   Next

   End Sub

1 个答案:

答案 0 :(得分:0)

我认为enrollPperiod应该是一个整数...应该修复它