我需要我的宏来提示我根据工作表名称选择工作表

时间:2013-06-04 22:19:22

标签: xml excel excel-vba worksheet vba

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

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

1 个答案:

答案 0 :(得分: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