0
Sub CheckBox7_Click()

   Dim cBox As CheckBox
   Dim LRow As Integer
   Dim LRange As String

   LName = Application.Caller
   Set cBox = ActiveSheet.CheckBoxes(LName)

   'Find row that checkbox resides in
   LRow = cBox.TopLeftCell.Row
   LRange = "B" & CStr(LRow)

   'Change text in column b, if checkbox is checked
   If cBox.Value > 0 Then
      ActiveSheet.Range(LRange).Value = "3300-0401"

   'Clear text in column b, if checkbox is unchecked
   Else
      ActiveSheet.Range(LRange).Value = Null
   End If

End Sub

我需要在从 b15 到 b40 开始的第一个可用单元格中输入值 3300-0401。此外,该日期将在字符串中的何处输入?

谢谢,让

4

1 回答 1

0

您可以使用以下内容写入范围 B15:B40 中的第一个空白单元格:

Sub WriteToFirstAvailableCellInRange()
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim firstEmptyCell As Range

    Set wb = ThisWorkbook
    Set ws = wb.Sheets("Sheet1")
    If ws.Range("B15").Value = "" Then
        Set firstEmptyCell = ws.Range("B15")
    Else
        If ws.Range("B16").Value = "" Then
            Set firstEmptyCell = ws.Range("B16")
        Else
            Set firstEmptyCell = ws.Range("B15").End(xlDown).Offset(1)
        End If
    End If

    If firstEmptyCell.Row < 41 Then
        firstEmptyCell.Value = "3300-0401"
    Else
        MsgBox "There aren't any empty cells in range B15:B40."
    End If
End Sub
于 2013-06-18T20:30:57.927 回答