从输入框中获取行和列

时间:2015-03-01 01:22:25

标签: excel vba excel-vba

背景资料

我有一个输入框,用于从我的用户那里获取日期以处理子过程。

问题

  1. 我无法从输入的值中获取行和列。
  2. 如何在用户选择的行返回结果,而不是固定位置cells(1, columns.count)
  3. 我尝试使用.address来查找行和列。但它会返回invalid qualifier你能解释一下原因吗?

  4. Sub functionLoop()
      Dim Nextoffday As Date
      Dim i As Integer
      Dim selectionRow As String
    
      Nextoffday = Application.InputBox(prompt:="Please select the second off day.", Title:="Pick second off day", Type:=8)
    
      For i = 1 To 30
        If AFPDAY(Nextoffday + i) <> "" Then
          ThisWorkbook.Worksheets(1).Cells(1, Columns.Count).End(xlToLeft).Offset(0, 1) = AFPDAY(Nextoffday + i)
        End If
      Next i
    End Sub
    

1 个答案:

答案 0 :(得分:1)

要查找所选单元用户的地址,请尝试使用以下代码:

Dim Nextoffday As Range 'defining Nextoffday as range instead of date

Set Nextoffday = Application.InputBox(prompt:="Please select the second off day.", Title:="Pick second off day", Type:=8) 'setting it to the user selected cell

MsgBox Nextoffday.Address ' .address will return the address of the cell selected by user

MsgBox Format(Nextoffday.Value, "mm.dd.yyyy") 'will convert the value in date format

Selection.Address将返回活动选定单元格的单元格引用。