2013-06-18 32 views
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 

我需要將值3300-0401輸入到從b15到b40開始的第一個可用單元格中。另外,這個日期將在哪裏輸入字符串?我試圖得到一個值進入特定的第一個單元格/行。我的論壇是:

謝謝你,讓

回答

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 
+0

謝謝你,它的工作原理,但我不能得到的價值複選框將從真/假更改爲3300-0401或其他任何內容。 –

相關問題