0

我正在运行以下宏,但希望它具有更多功能。此电子表格用于维护客户和跟踪多个州内的销售价值。我为我工作的每个状态都标记了工作簿。我希望宏提示我要从当前宏输入数据的状态。我可以在此宏中添加一些内容,以便它首先提示我根据工作表名称选择工作表吗?

Sub TestMacro()
Dim dblRow As Double, dtDate As Date, strCustomer As String
Dim strAddress As String, strZip As String, strEst As String
    dblRow = InputBox("What Row to Enter On")
    dtDate = InputBox("Date", , Date)
    strCustomer = InputBox("Customer")
    strAddress = InputBox("Address")
    strZip = InputBox("Zip Code")
    strEst = InputBox("Estimated Value")
    Range("A" & dblRow).Value = dtDate
    Range("B" & dblRow).Value = strCustomer
    Range("C" & dblRow).Value = strAddress
    Range("D" & dblRow).Value = strZip
    Range("E" & dblRow).Value = strEst
End Sub
4

1 回答 1

0

我想到了。这是我的代码的工作结果。

Sub EnterContact()
Dim lastrow As Long, strCust As String, strAddress As String
Dim strTown As String, strZip As String, strPhone As String
Dim strFax As String, strEmail As String, strContact As String
Dim strPrior As String, strOrg As String, strProj As String

With Sheets("Oregon")
    lastrow = .Range("A" & .Rows.Count).End(xlUp).Row + 1

    strCust = InputBox("Enter Customer")
    strAddress = InputBox("Enter Address")
    strTown = InputBox("Enter Town")
    strZip = InputBox("Enter Zip Code")
    strPhone = InputBox("Enter Phone Number")
    strFax = InputBox("Enter Fax Number")
    strEmail = InputBox("Enter Email Address")
    strContact = InputBox("Enter Contact Name")
    strPrior = InputBox("Enter Priority Level")
    strOrg = InputBox("Enter Organization")
    strProj = InputBox("Enter Projected Dollar Amount")
    Range("A" & lastrow).Value = strCust
    Range("B" & lastrow).Value = strAddress
    Range("C" & lastrow).Value = strTown
    Range("D" & lastrow).Value = strZip
    Range("E" & lastrow).Value = strPhone
    Range("F" & lastrow).Value = strFax
    Range("G" & lastrow).Value = strEmail
    Range("H" & lastrow).Value = strContact
    Range("I" & lastrow).Value = strPrior
    Range("J" & lastrow).Value = strOrg
    Range("K" & lastrow).Value = strProj

Dim LRow As Long
'Find last row in Column A with content
   LRow = Cells(Rows.Count, 1).End(xlUp).Offset(0, 0).Row
   Rows("5:" & LRow).Sort Key1:=.Range("C3"), _
      Order1:=xlAscending, Header:=xlNo, _
      OrderCustom:=1, MatchCase:=False, _
      Orientation:=xlTopToBottom

    End With
End Sub
于 2013-06-10T18:56:28.533 回答