Adding "buttons" to an attendance form.

msann

New Member
Joined
Sep 24, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello, everyone.
I'm very new to VBA, so bare with me. We have an attendance form that we use where students scan their IDs to a spreadsheet and we click on buttons to mark them present (P), tardy (T), or first time in class (FTC). Since half of our students are still virtual, I would like to add two more buttons, one for remote asynchronous present (RAP) and one for first time in class - remote (FTC-R). I tried copying the code but I keep getting an error. Not sure what I am doing wrong. I tried to post my spreadsheet using XL2BB but the buttons were showing up.

Here is the code from the spreadsheet.
VBA Code:
Sub MarkFTC()

Dim PeriodWS, IDS As Worksheet
Dim Period, CheckID, IDreverse, TardyAddress, FirstName, LastName As String
Dim TDay As Date
Dim dateCell, IDRange, IDReverseRange As Range
Dim i, j, lastRow, IDlastRow As Integer
Set IDS = Sheets("ID Scan")
TardyAddress = Selection.Address
Application.ScreenUpdating = False
TDay = Date


Period = IDS.Range("C1").Value
Set PeriodWS = Sheets(Period)
lastRow = PeriodWS.Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
Set dateCell = PeriodWS.Range("1:1").Find(what:=TDay)
If Not dateCell Is Nothing Then
    For i = 2 To lastRow
        CheckID = PeriodWS.Range("D" & i).Value
       
        Set IDRange = IDS.Range(TardyAddress).Find(what:=CheckID)
       
        If Not IDRange Is Nothing Then
            If Not PeriodWS.Cells(i, dateCell.Column).Interior.Color = RGB(128, 128, 128) Then
            IDS.Cells(IDRange.Row, "D").Value = "Marked FTC"
            PeriodWS.Cells(i, dateCell.Column).Value = "FTC"
            PeriodWS.Cells(i, dateCell.Column).Interior.Color = RGB(146, 208, 80)
            End If
        End If
    Next
Else
    MsgBox "Date Not in Range"
End If
IDS.Range("C1").Clear
IDlastRow = IDS.Cells(Rows.Count, 1).End(xlUp).Row
For j = 1 To IDlastRow
IDreverse = IDS.Range("A" & j).Value
Set IDReverseRange = PeriodWS.Range("D:D").Find(what:=IDreverse)

If IDReverseRange Is Nothing Then
    IDS.Cells(j, 3).Value = "ID not in " & Period
    IDS.Cells(j, 3).Interior.Color = RGB(255, 0, 0)
ElseIf PeriodWS.Cells(IDReverseRange.Row, dateCell.Column).Interior.Color = RGB(128, 128, 128) Then
    IDS.Cells(j, 3).Value = "Schedule Change"
Else
    FirstName = PeriodWS.Range("B" & IDReverseRange.Row).Value
    LastName = PeriodWS.Range("A" & IDReverseRange.Row).Value
    IDS.Cells(j, 3).Value = LastName & ", " & FirstName


End If

Next
IDS.UsedRange.Columns.AutoFit
Application.ScreenUpdating = True
End Sub

----------------

Here is mine. But I keep getting errors. Any suggestions would be great. Thanks.

VBA Code:
Private Sub Mark_RAP()
UserForm7.Show
End Sub

Sub MarkRAP()

Dim PeriodWS, IDS As Worksheet
Dim Perid, CheckID, IDreverse, TardyAddress, FirstName, LastName As String
Dim TDay As Date
Dim dateCell, IDRange, IDReverseRange As Range
Dim i, j, lastRow, IDlastRow As Integer
Set IDS = Sheets("ID Scan")
TardyAddress = Selection.Address
Application.ScreenUpdating = False
TDay = Date

Period = IDS.Range("C1").Value
Set PeriodWS = Sheets("ID Scan")
lastRow = PeriodWS.Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
Set dateCell = PeriodWS.Range("1:1").Find(what:=TDay)
If Not dateCell Is Nothing Then
For i = 2 To lastRow
        CheckID = PeriodWS.Range("D" & i).Value
       
        Set IDRange = IDS.Range(TardyAddress).Find(what:=CheckID)
       
        If Not IDRange Is Nothing Then
            If Not PeriodWS.Cells(i, dateCell.Column).Interior.Color = RGB(128, 128, 128) Then
            IDS.Cells(IDRange.Row, "D").Value = "Marked RAP"
            PeriodWS.Cells(i, dateCell.Column).Value = "RAP"
            PeriodWS.Cells(i, dateCell.Column).Interior.Color = RGB(255, 153, 0)
            End If
        End If
    Next
Else
    MsgBox "Date Not in Range"
End If
IDS.Range("C1").Clear
IDlastRow = IDS.Cells(Rows.Count, 1).End(xlUp).Row
For j = 1 To IDlastRow
IDreverse = IDS.Range("A" & j).Value
Set IDReverseRange = PeriodWS.Range("D:D").Find(what:=IDreverse)

If IDReverseRange Is Nothing Then
    IDS.Cells(j, 3).Value = "ID not in " & Period
    IDS.Cells(j, 3).Interior.Color = RGB(255, 0, 0)
ElseIf PeriodWS.Cells(IDReverseRange.Row, dateCell.Column).Interior.Color = RGB(128, 128, 128) Then
    IDS.Cells(j, 3).Value = "Schedule Change"
Else
    FirstName = PeriodWS.Range("B" & IDReverseRange.Row).Value
    LastName = PeriodWS.Range("A" & IDReverseRange.Row).Value
    IDS.Cells(j, 3).Value = LastName & ", " & FirstName


End If

Next
IDS.UsedRange.Columns.AutoFit
Application.ScreenUpdating = True
End Sub
 
Last edited by a moderator:

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hello, everyone.
I'm very new to VBA, so bare with me. We have an attendance form that we use where students scan their IDs to a spreadsheet and we click on buttons to mark them present (P), tardy (T), or first time in class (FTC). Since half of our students are still virtual, I would like to add two more buttons, one for remote asynchronous present (RAP) and one for first time in class - remote (FTC-R). I tried copying the code but I keep getting an error. Not sure what I am doing wrong. I tried to post my spreadsheet using XL2BB but the buttons were showing up.
Sorry, buttons were NOT showing up.

_Attendance_092019.xlsm
ABCDEFGHIJKLM
1
2
3
4
5
6
7
8
9
10
11Select the ID numbers before clicking
12the buttons below to change the code.
13Or manually change the Period tab.
14This button is ONLY used the
15first time you create the file
16
17
18
19
20
21No Shows must be entered by hand!
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
ID Scan
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,573
Members
449,089
Latest member
Motoracer88

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