通过偏移更改下一循环中的字段

时间:2013-08-02 11:46:41

标签: vba loops excel-vba offset excel

以下是我的内容。我需要循环来改变RC = MyHost.keys(DestinationE) 当它经过下一个循环时,在同一列I10中I8到两行的值。宏可以工作但是当它循环时它会从中提取相同的数据。我在这做错了什么。在我的脑袋爆炸之前请帮忙。非常感谢!

Sub PTPMLRs()
Dim MyHost As Object
Dim HE As Object
Set HE = CreateObject("HostExplorer")
Set MyHost = HE.CurrentHost
Dim RC As Integer

Dim Lsheet As Worksheet
Set Lsheet = ThisWorkbook.Worksheets("PTPMLRs")


Dim Station1 As String
Dim Station1Loc As Range

Dim Station2 As String
Dim Station2Loc As Range

Dim Station3 As String
Dim Station3Loc As Range

Dim DestinationE As String
Dim DestinationELoc As Range

Dim DestinationN As String
Dim DestinationNLoc As Range

Dim DestinationA As String
Dim DestinationALoc As Range

Dim Vehicle As String
Dim VehicleLoc As Range

Dim AllVeh As String
Dim AllVehLoc As Range

Dim BeginDate As String
Dim BeginDateLoc As Range

Dim EndDate As String
Dim EndDateLoc As Range

Dim BeginTime As String
Dim BeginTimeLoc As Range

Dim EndTime As String
Dim EndTimeLoc As Range

Dim Inv As String
Dim InvLoc As Range


Dim Mlr As String
Dim MlrLoc As Range

Set Station1Loc = Lsheet.Range("I6")
Set Station2Loc = Lsheet.Range("M6")
Set Station3Loc = Lsheet.Range("Q6")

Set DestinationELoc = Lsheet.Range("I8")
Set DestinationNLoc = Lsheet.Range("M8")
Set DestinationALoc = Lsheet.Range("Q8")

Set VehicleLoc = Lsheet.Range("E6")
Set AllVehLoc = Lsheet.Range("E8")
Set BeginDateLoc = Lsheet.Range("E10")
Set EndDateLoc = Lsheet.Range("E12")
Set BeginTimeLoc = Lsheet.Range("E14")
Set EndTimeLoc = Lsheet.Range("E16")
Set InvLoc = Lsheet.Range("E18")
Set MlrLoc = Lsheet.Range("E20")

    Station1 = Station1Loc.Value
    Station2 = Station2Loc.Value
    Station3 = Station3Loc.Value

    DestinationE = DestinationELoc.Value
    DestinationN = DestinationNLoc.Value
    DestinationA = DestinationALoc.Value




    RC = MyHost.Runcmd("pF2")
    RC = MyHost.keys(Station1)
    RC = MyHost.Runcmd("pF3")
    RC = MyHost.Runcmd("TAB")
    RC = MyHost.Runcmd("TAB")
    RC = MyHost.Runcmd("TAB")



    Do Until DestinationELoc.Value = ""

    Vehicle = VehicleLoc.Value
    AllVeh = AllVehLoc.Value
    BeginDate = BeginDateLoc.Value
    EndDate = EndDateLoc.Value
    BeginTime = BeginTimeLoc.Value
    EndTime = EndTimeLoc.Value
    Inv = InvLoc.Value
    Mlr = MlrLoc.Value



    RC = MyHost.Runcmd("pF2")
    RC = MyHost.keys(DestinationE)
    RC = MyHost.Runcmd("pF3")
    RC = MyHost.Runcmd("PAGE-DOWN")
    RC = MyHost.Runcmd("INSERT-HERE")
    RC = MyHost.Runcmd("TAB")
    RC = MyHost.Runcmd("TAB")
    RC = MyHost.keys(Vehicle)
    RC = MyHost.Runcmd("TAB")
    RC = MyHost.keys(BeginDate)
    RC = MyHost.Runcmd("TAB")
    RC = MyHost.keys(EndDate)
    RC = MyHost.Runcmd("PAGE-DOWN")
    RC = MyHost.keys(BeginTime)
    RC = MyHost.Runcmd("TAB")
    RC = MyHost.keys(EndTime)
    RC = MyHost.Runcmd("TAB")
    RC = MyHost.keys(Inv)
    RC = MyHost.Runcmd("TAB")
    RC = MyHost.keys(Mlr)
    RC = MyHost.Runcmd("pF4")
    RC = MyHost.keys(AllVeh)
    RC = MyHost.Runcmd("ENTER")
    RC = MyHost.Runcmd("ENTER")
    RC = MyHost.Runcmd("PAGE-UP")
    RC = MyHost.Runcmd("PAGE-UP")

    Set DestinationELoc = DestinationELoc.Offset(2, 0)




Loop



End Sub

1 个答案:

答案 0 :(得分:0)

添加第二行:

Set DestinationELoc = DestinationELoc.Offset(2, 0)
DestinationE = DestinationELoc.Value