当我的条件满足时,vba不会退出循环

时间:2019-12-13 15:50:59

标签: excel vba loops

您好,我有一些代码根据两个条件(日期和容器大小)从工作表中获取一个值,然后将该值填写到另一张表的相应字段中。似乎所有这些都与代码保持一致,但是我在运行它时却遇到了if语句问题,它设法找到两个值,并且在语句为true时vba不会退出循环。这也是我第一次使用case函数,所以不确定我的语法是否100%正确。预先感谢您的帮助

Dim R As Integer
Dim VESSELCLASS, VLCC, Suezmax, aframax, Panamax As String
Dim TDValue, NewTD As String



LastrowTD = Worksheets("TDS").Cells(Rows.Count, 1).End(xlUp).Row

VESSELCLASS = Worksheets("Petrobras").Cells(Rows.Count, 2).End(xlUp).Offset(0, 3).Text

NewTD = Worksheets("Petrobras").Cells(Rows.Count, 2).End(xlUp).Offset(1, -1).Text

VLCC = Worksheets("TDS").Cells(1, 2).Text
Suezmax = Worksheets("TDS").Cells(1, 3).Text
aframax = Worksheets("TDS").Cells(1, 4).Text
Panamax = Worksheets("TDS").Cells(1, 5).Text




    For R = 2 To LastrowTD

       TDValue = Worksheets("TDS").Cells(R, 1).Text


 If NewTD = TDValue Then
    End If
    Next

    Select Case VESSELCLASS


      Case VLCC
Worksheets("TDS").Cells(R, 2).Value = Worksheets("Petrobras").Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Value
      Case Suezmax
Worksheets("TDS").Cells(R, 3).Value = Worksheets("Petrobras").Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Value
       Case aframax
Worksheets("TDS").Cells(R, 4).Value = Worksheets("Petrobras").Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Value
       Case Panamax
Worksheets("TDS").Cells(R, 5).Value = Worksheets("Petrobras").Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Value





    End Select


End Sub

0 个答案:

没有答案