Need help programming a simple Excel database with VisualBasic

Status
Not open for further replies.

scottrssll

New Member
Joined
Jan 8, 2016
Messages
11
Hello,

I'm currently building a disciplinary report log for work. The design of the log is simple; I have a table in Sheet 1 with rows corresponding to employee names. Each column represents a general category of possible infractions (e.g. safety; cell phone usage; failure to comply with procedures). I want to be able to click a cell to see and input specific infraction data (Date, Time, Supervisor), have it save to a database, and have the cell change format relative to the number of infractions (3 being most severe) with a message that pops up after 3 infractions asking if the employee was counselled and if that cell should be reset.

So far, I have this formula for the cells, which I don't like, to set the reference cells for the data and to offer a quick status message. I would prefer if the cells changed from Green, to Yellow, to Orange, to Red:

=IF(AND(ISTEXT(Sheet2!A1),ISTEXT(Sheet2!A2),ISTEXT(Sheet2!A3)),"WRITE UP","GOOD")

For the inputbox and msgbox aspect, I've been using Visual Basic, and I'm struggling greatly. The Code won't work at all and is missing the function to display the current infraction data. Furthermore, if I continue with the code as it is I will have to write the entire program over and over for every cell. But, since the cells have to reference a specific employee and specific category of violation, I don't know of a better way using VisualBasic.

Please help! I'm desperate! Here's the code so far:

Code:
Option Explicit
Sub TransgressionLog_Click(ByVal Target As Range)
    If Selection.Count = 1 Then
        If Not Intersect(Target, Range("D4")) Is Nothing Then
            If IsText(Sheet2!D1) And IsText(Sheet2!D2) And IsText(Sheet2!D3) Then
                Response = MsgBox("Has the counseling been completed?", vbYesNo, "Reset Counseling")
                If Response = msgboxresult.yes Then
                    Sub sbClearCellsOnlyData()
                    Range("Sheet2!d1:Sheet2!d3").ClearContents
                    End Sub
                Else
                    Response = MsgBox("Councelling Must Be Completed To Reset Strikes", vbOKOnly, "Reset Counseling")
                End If
            Else
                Sub cmdAddData_Click()
                    Dim strTransgression$
                    Dim sw1 As Boolean


                     strTransgression = InputBox("Please Describe the Infraction", , "Transgression Report")


                          With Sheets("2")
                          lngLstRow = .UsedRange.Rows.Count + .UsedRange.Row
                          .Range("d1:d3" & lngLstRow).Value = strUserName
                          End With


                         MsgBox "Transgression Successfully Added!", _
                         vbExclamation + vbOKOnly, _
                         "Added!"
                          End If


                    myEnd:
                    End Sub
            End If


        End If
    End If


End Sub


[Code/]
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Status
Not open for further replies.

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top