如何使用 InputBox 选择一个单元格并使用该列的值?我修剪了大部分代码以使其适合,因此某些变量将未声明。
子 MacroForTransfers()
Application.ScreenUpdating = False
' Declare variables for sheet names and adding new sheet
SheetName1 = "Original"
SheetName2 = "New"
ActiveSheet.Name = SheetName1
Sheets.Add.Name = SheetName2
Sheets(SheetName2).Select
' End of declare variables for sheet names
Dim shipDate, truckRoute, ware, custPurchaseOrder, jobName, shipVia As String
Dim unitSelect As Range
shipVia = Application.InputBox(Prompt:="Please enter the ship via: ", Title:="Enter Ship Via", Default:="Enter two digit ship via here")
If shipVia = vbNullString Then
Exit Sub
End If
shipDate = Application.InputBox(Prompt:="Please enter the date order needs to ship (e.g. 040113): ", Title:="Enter Ship Date", Default:="Enter six digit ship date here")
If shipDate = vbNullString Then
Exit Sub
End If
custPurchaseOrder = Application.InputBox(Prompt:="Please enter customer PO#: ", Title:="Enter Customer PO#", Default:="Enter customer PO# here")
If custPurchaseOrder = vbNullString Then
Exit Sub
End If
ware = Application.InputBox(Prompt:="Please enter warehouse to receive transfer: ", Title:="Enter Warehouse to Receive Transfer", Default:="Enter three digit warehouse code here")
If ware = vbNullString Then
Exit Sub
End If
jobName = Application.InputBox(Prompt:="Please enter job name: ", Title:="Enter Job Name", Default:="Enter job name here")
If jobName = vbNullString Then
Exit Sub
End If
truckRoute = Application.InputBox(Prompt:="Please enter the truck route: ", Title:="Enter Truck Route", Default:="Enter two digit truck route here")
If truckRoute = vbNullString Then
Exit Sub
End If
Set unitSelect = Application.InputBox(Prompt:="Please enter the unit column: ", Type:=8)
Range("A1").Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""a300002"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[enter]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys " & Chr(34) & shipVia & Chr(34)
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys " & Chr(34) & shipDate & Chr(34)
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[tab]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys " & Chr(34) & custPurchaseOrder & Chr(34)
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[down]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[tab]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""man"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[tab]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys " & Chr(34) & ware & Chr(34)
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[down]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[down]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[down]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[down]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[down]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[down]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[down]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[tab]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[tab]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys " & Chr(34) & jobName & Chr(34)
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[enter]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys " & Chr(34) & truckRoute & Chr(34)
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[enter]"""
Sheets(SheetName1).Select ' Select the Original Sheet
lastRow = 65536
For row = 3 To lastRow
item = Range("A" & row).Value
If item <> "" Then
Transfer = Range("U" & row).Value
unit = unitSelect.Parent.Cells(row, unitSelect.Column).Value
If Transfer > 0 Then
Sheets(SheetName2).Select ' Select the New Sheet
lastRow = Cells(Rows.Count, "A").End(xlUp).row ' Find the last cell that has data in Column A
Range("A" & lastRow).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[backtab]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""man"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys " & Chr(34) & item & Chr(34)
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[up]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[tab]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[tab]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[tab]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[tab]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[tab]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[tab]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys " & Chr(34) & Transfer & Chr(34)
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[field+]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys " & Chr(34) & unit & Chr(34)
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[enter]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[tab]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[tab]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[tab]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[tab]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""b"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[enter]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[enter]"""
Sheets(SheetName1).Select ' Select the Original Sheet
End If
End If
Next row
Sheets(SheetName2).Select ' Select the New Sheet
lastRow = Cells(Rows.Count, "A").End(xlUp).row ' Find the last cell that has data in Column A
Range("A" & lastRow).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[pf7]"""
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "autECLSession.autECLPS.SendKeys ""[pf7]"""
结束子