0

在上一个问题之后,我不得不打开一个新问题,我必须减少和增加一个数字,该数字位于下面的链接中

更改 VBA 宏代码以更改数字

这是我正在尝试使用的代码,我几乎可以使用它,但是在某个地方出了问题。

Bulkwks.[B5]M20

historywks.[a2]是时候

historywks.[b2]是名字

historywks.[C2]m201001

Sub bulkON_Click()

    Dim trnwkbk As Workbook
    Dim Bulkwks As Worksheet
    Dim Deswkbk As Workbook
    Dim LogNum As Range, LastNum, NewNum, 
    Dim historywks As Worksheet

    Dim nextRow As Long
    Dim lOR As Long
    Dim myIn As String
    Dim myLeft As String
    Dim myMid As Integer, myRight As Integer, i As Integer
    Dim myOut As String

    Set trnwkbk = Workbooks("Transport.xls")
    Set Bulkwks = trnwkbk.Worksheets("Bulk")

    lOR = MsgBox("Have you selected the right MIS or HUB or PSA number?", vbQuestion + vbYesNo, "Number Order")
    If lOR = vbNo Then
    MsgBox "Please select right Order Number"
    Else
    Application.ScreenUpdating = False
    ' for testing i just made it post in test sheet in same workbook 
    'Set Deswkbk = Workbooks.Open("\\dunton01\Inspections\TRANSPORT\New_transport\data\Febuary_2013.xls")
    'Set historywks = Deswkbk.Worksheets("Data")
    Set historywks = Worksheets("test")


    Set LogNum = historywks.[C2]


    With historywks
          nextRow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row
    End With

    If LogNum(2, 1) = "" Then
        LastNum = LogNum
    Else
        LastNum = LogNum(LogNum.End(xlDown).Row - 1, 1)
    End If

    NewNum = Bulkwks.[B5] & Val(Mid(LastNum, 2)) + 1

    If LogNum(2, 1) = "" Then
       LogNum(2, 1) = NewNum

    Else

    myIn = LogNum
    myLeft = Left(myIn, 1)
    myMid = CInt(Mid(myIn, 2, 2))
    myRight = CInt(Right(myIn, 4))
    myOut = myLeft & Format(myMid, "00") & Format(myRight, "0000")
    i = 0

    Debug.Print "IN:        " & myIn
    Debug.Print "BROKEN UP: " & myOut

    Do Until myMid = -1
        Debug.Print "ITERATION " & Format(i, "00") & ": " & myLeft & Format(myMid, "00") & Format(myRight, "0000")

        myMid = myMid - 1
        myRight = myRight + 1
        myOut = myLeft & Format(myMid, "00") & Format(myRight, "0000")
        i = i + 1

     With historywks
          'enter date and time stamp in record
          With .Cells(nextRow, "A")
              .Value = Now
              .NumberFormat = "mm/dd/yyyy hh:mm:ss"
            End With

          'enter user name in column B
          .Cells(nextRow, "B").Value = Application.UserName
          .Cells(nextRow, "C").Value = myIn
   End With ' for testing i just disabled this Deswkbk.save
    Loop
    ' for testing i just disabled this 
    'Deswkbk.Close savechanges:=True
    Application.ScreenUpdating = True

    Bulkwks.[E3] = NewNum

    End If

    ' for testing i just disabled this  
    'Call File_In_Network_Folder

   End If
  End Sub
4

1 回答 1

1

您需要使用该myOut变量。

.Cells(nextRow, "C").Value = myOut
于 2013-02-21T08:26:42.847 回答