Question Locked

Visual Basic Help

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

If there's anyone out there who could hep me with Visual Basic, I'm trying to program a macro that records the current date (for checking in a laptop that has been checked out) in excel. I've gotten the button to bring up a window with bubble selections for each laptop and projector that we have with a check in button and a cancel button. The cancel button works (no biggie) but I can't get it to enter in the date to the corresponding checked out piece of equipment. Keeping in mind, I have never even screwed around with Visual Basic until yesterday, so I'm just getting severely frustrated instead of progressing further.

Thanks!
Alex

6 replies

by awillman

Remember, this is day 2 of me using VB, so yeah. Try not to laugh.

Private Sub CheckinButton_Click()

ActiveWorkbook.Sheets("Laptop Checkout").Activate

Range("A1").Select

Do

If IsEmpty(ActiveCell) = False Then

If Floater1 = yes Then

ActiveCell.Offset(0, 7).Select

End If

IsEmpty(ActiveCell) = True

ActiveCell.Value = Date

ActiveCell.Offset(0, 7) = Date

End Sub

Private Sub cmdCancel_Click()
Unload Me
End Sub

by awillman

Private Sub cmdCancel_Click()
Unload Me
End Sub

Private Sub cmdClearForm_Click()
Call UserForm_Initialize
End Sub

Private Sub cmdOK_Click()

ActiveWorkbook.Sheets("Laptop Checkout").Activate

Range("A1").Select

Do

If IsEmpty(ActiveCell) = False Then

ActiveCell.Offset(1, 0).Select

End If

Loop Until IsEmpty(ActiveCell) = True

ActiveCell.Value = txtName.Value

ActiveCell.Offset(0, 1) = txtDepartment.Value

ActiveCell.Offset(0, 2) = txtPhone.Value

ActiveCell.Offset(0, 3) = txtCheckout.Value

ActiveCell.Offset(0, 4) = txtReturn.Value

ActiveCell.Offset(0, 5) = txtBrand.Value

ActiveCell.Offset(0, 6) = txtModel.Value

If chkLaptop = True Then
ActiveCell.Offset(0, 9).Value = "Yes"
Else
ActiveCell.Offset(0, 9).Value = "No"
End If

If chkPower = True Then
ActiveCell.Offset(0, 10).Value = "Yes"
Else
ActiveCell.Offset(0, 10).Value = "No"
End If

If chkModem = True Then
ActiveCell.Offset(0, 11).Value = "Yes"
Else
ActiveCell.Offset(0, 11).Value = "No"
End If

If chkFloppy = True Then
ActiveCell.Offset(0, 12).Value = "Yes"
Else
ActiveCell.Offset(0, 12).Value = "No"
End If

If chkMouse = True Then
ActiveCell.Offset(0, 13).Value = "Yes"
Else
ActiveCell.Offset(0, 13).Value = "No"
End If

If chkSpare = True Then
ActiveCell.Offset(0, 14).Value = "Yes"
Else
ActiveCell.Offset(0, 14).Value = "No"
End If

If chkNetwork = True Then
ActiveCell.Offset(0, 15).Value = "Yes"
Else
ActiveCell.Offset(0, 15).Value = "No"
End If

If chkCD = True Then
ActiveCell.Offset(0, 16).Value = "Yes"
Else
ActiveCell.Offset(0, 16).Value = "No"
End If

If chkOther = True Then
ActiveCell.Offset(0, 17).Value = "Yes"
Else
ActiveCell.Offset(0, 17).Value = "No"
End If

ActiveCell.Offset(0, 18) = txtOther.Value

Call UserForm_Initialize

Range("A1").Select

End Sub

Private Sub Label6_Click()

End Sub

Private Sub UserForm_Initialize()

txtName.Value = ""
txtDepartment.Value = ""
txtPhone.Value = ""
txtCheckout.Value = Date
txtReturn.Value = ""
txtBrand.Value = ""
txtModel.Value = ""

chkLaptop = False
chkPower = False
chkModem = False
chkFloppy = False
chkMouse = False
chkSpare = False
chkNetwork = False
chkCD = False
chkOther = False

txtOther.Value = ""

End Sub

by thumbsup2

Since, in Excel, today's date is input by typing =today() ... the code in a simple macro to select the cell and input today's date would be:

Range("C3").Select
ActiveCell.FormulaR1C1 = "=TODAY()"

------

So, see if you can incorporate that into your existing code.

by awillman

My dates will be in column H.

How should that formula look?

This discussion is closed to new replies.