Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports Excel = Microsoft.Office.Interop.Excel
- Imports System.Data
- Public Class Form1
- Dim APP As New Excel.Application
- Dim worksheet As Excel.Worksheet
- Dim workbook As Excel.Workbook
- Dim TotalEntriesTemp As Long = 0
- Dim Entries As Long = 0
- Dim TotalEntries As Long = 0
- Dim State As String = ""
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- 'Add Filters to ComboBox
- Filter1.Items.Add("STATE")
- End Sub
- Private Sub btnLoad_Click(sender As Object, e As EventArgs) Handles btnLoad.Click
- 'Make State(String) = Filter2.Text
- State = Filter2.Text
- 'Make TextBoxes visible=false
- txtBN1.Visible = False
- txtFACID1.Visible = False
- txtMGMT1.Visible = False
- txtCOMMENT1.Visible = False
- txtCITY1.Visible = False
- txtPM1.Visible = False
- txtTYPE1.Visible = False
- txtACTIVITY1.Visible = False
- txtBN2.Visible = False
- txtFACID2.Visible = False
- txtMGMT2.Visible = False
- txtCOMMENT2.Visible = False
- txtCITY2.Visible = False
- txtPM2.Visible = False
- txtTYPE2.Visible = False
- txtACTIVITY2.Visible = False
- txtBN3.Visible = False
- txtFACID3.Visible = False
- txtMGMT3.Visible = False
- txtCOMMENT3.Visible = False
- txtCITY3.Visible = False
- txtPM3.Visible = False
- txtTYPE3.Visible = False
- txtACTIVITY3.Visible = False
- txtBN4.Visible = False
- txtFACID4.Visible = False
- txtMGMT4.Visible = False
- txtCOMMENT4.Visible = False
- txtCITY4.Visible = False
- txtPM4.Visible = False
- txtTYPE4.Visible = False
- txtACTIVITY4.Visible = False
- txtBN5.Visible = False
- txtFACID5.Visible = False
- txtMGMT5.Visible = False
- txtCOMMENT5.Visible = False
- txtCITY5.Visible = False
- txtPM5.Visible = False
- txtTYPE5.Visible = False
- txtACTIVITY5.Visible = False
- txtBN6.Visible = False
- txtFACID6.Visible = False
- txtMGMT6.Visible = False
- txtCOMMENT6.Visible = False
- txtCITY6.Visible = False
- txtPM6.Visible = False
- txtTYPE6.Visible = False
- txtACTIVITY6.Visible = False
- txtBN7.Visible = False
- txtFACID7.Visible = False
- txtMGMT7.Visible = False
- txtCOMMENT7.Visible = False
- txtCITY7.Visible = False
- txtPM7.Visible = False
- txtTYPE7.Visible = False
- txtACTIVITY7.Visible = False
- txtBN8.Visible = False
- txtFACID8.Visible = False
- txtMGMT8.Visible = False
- txtCOMMENT8.Visible = False
- txtCITY8.Visible = False
- txtPM8.Visible = False
- txtTYPE8.Visible = False
- txtACTIVITY8.Visible = False
- 'workbook = APP.Workbooks.Open("Path\AZ.xlsx")
- 'Load the correct worksheet
- workbook = APP.Workbooks.Open("C:\Users\USER\Desktop\" & State & ".xlsx")
- worksheet = workbook.Worksheets("Sheet1")
- 'Count entries
- TotalEntries = worksheet.Range("B1048576").End(Excel.XlDirection.xlUp).Row
- TotalEntriesTemp = TotalEntries
- If TotalEntries > 7 Then
- Entries = 7
- TotalEntriesTemp = TotalEntriesTemp - (TotalEntriesTemp - Entries)
- btnNext.Visible = True
- Else
- Entries = TotalEntries
- End If
- 'Display corrent number of tables
- If Entries = 0 Then
- MsgBox("No Entries!")
- End If
- If Entries <= 2 Then
- txtBN1.Visible = True
- txtFACID1.Visible = True
- txtMGMT1.Visible = True
- txtCOMMENT1.Visible = True
- txtCITY1.Visible = True
- txtPM1.Visible = True
- txtTYPE1.Visible = True
- txtACTIVITY1.Visible = True
- End If
- If Entries = 2 Then
- txtBN2.Visible = True
- txtFACID2.Visible = True
- txtMGMT2.Visible = True
- txtCOMMENT2.Visible = True
- txtCITY2.Visible = True
- txtPM2.Visible = True
- txtTYPE2.Visible = True
- txtACTIVITY2.Visible = True
- txtBN1.Visible = True
- txtFACID1.Visible = True
- txtMGMT1.Visible = True
- txtCOMMENT1.Visible = True
- txtCITY1.Visible = True
- txtPM1.Visible = True
- txtTYPE1.Visible = True
- txtACTIVITY1.Visible = True
- End If
- If Entries = 3 Then
- txtBN3.Visible = True
- txtFACID3.Visible = True
- txtMGMT3.Visible = True
- txtCOMMENT3.Visible = True
- txtCITY3.Visible = True
- txtPM3.Visible = True
- txtTYPE3.Visible = True
- txtACTIVITY3.Visible = True
- txtBN2.Visible = True
- txtFACID2.Visible = True
- txtMGMT2.Visible = True
- txtCOMMENT2.Visible = True
- txtCITY2.Visible = True
- txtPM2.Visible = True
- txtTYPE2.Visible = True
- txtACTIVITY2.Visible = True
- txtBN1.Visible = True
- txtFACID1.Visible = True
- txtMGMT1.Visible = True
- txtCOMMENT1.Visible = True
- txtCITY1.Visible = True
- txtPM1.Visible = True
- txtTYPE1.Visible = True
- txtACTIVITY1.Visible = True
- End If
- If Entries = 4 Then
- txtBN4.Visible = True
- txtFACID4.Visible = True
- txtMGMT4.Visible = True
- txtCOMMENT4.Visible = True
- txtCITY4.Visible = True
- txtPM4.Visible = True
- txtTYPE4.Visible = True
- txtACTIVITY4.Visible = True
- txtBN3.Visible = True
- txtFACID3.Visible = True
- txtMGMT3.Visible = True
- txtCOMMENT3.Visible = True
- txtCITY3.Visible = True
- txtPM3.Visible = True
- txtTYPE3.Visible = True
- txtACTIVITY3.Visible = True
- txtBN2.Visible = True
- txtFACID2.Visible = True
- txtMGMT2.Visible = True
- txtCOMMENT2.Visible = True
- txtCITY2.Visible = True
- txtPM2.Visible = True
- txtTYPE2.Visible = True
- txtACTIVITY2.Visible = True
- txtBN1.Visible = True
- txtFACID1.Visible = True
- txtMGMT1.Visible = True
- txtCOMMENT1.Visible = True
- txtCITY1.Visible = True
- txtPM1.Visible = True
- txtTYPE1.Visible = True
- txtACTIVITY1.Visible = True
- End If
- If Entries = 5 Then
- txtBN5.Visible = True
- txtFACID5.Visible = True
- txtMGMT5.Visible = True
- txtCOMMENT5.Visible = True
- txtCITY5.Visible = True
- txtPM5.Visible = True
- txtTYPE5.Visible = True
- txtACTIVITY5.Visible = True
- txtBN4.Visible = True
- txtFACID4.Visible = True
- txtMGMT4.Visible = True
- txtCOMMENT4.Visible = True
- txtCITY4.Visible = True
- txtPM4.Visible = True
- txtTYPE4.Visible = True
- txtACTIVITY4.Visible = True
- txtBN3.Visible = True
- txtFACID3.Visible = True
- txtMGMT3.Visible = True
- txtCOMMENT3.Visible = True
- txtCITY3.Visible = True
- txtPM3.Visible = True
- txtTYPE3.Visible = True
- txtACTIVITY3.Visible = True
- txtBN2.Visible = True
- txtFACID2.Visible = True
- txtMGMT2.Visible = True
- txtCOMMENT2.Visible = True
- txtCITY2.Visible = True
- txtPM2.Visible = True
- txtTYPE2.Visible = True
- txtACTIVITY2.Visible = True
- txtBN1.Visible = True
- txtFACID1.Visible = True
- txtMGMT1.Visible = True
- txtCOMMENT1.Visible = True
- txtCITY1.Visible = True
- txtPM1.Visible = True
- txtTYPE1.Visible = True
- txtACTIVITY1.Visible = True
- End If
- If Entries = 6 Then
- txtBN6.Visible = True
- txtFACID6.Visible = True
- txtMGMT6.Visible = True
- txtCOMMENT6.Visible = True
- txtCITY6.Visible = True
- txtPM6.Visible = True
- txtTYPE6.Visible = True
- txtACTIVITY6.Visible = True
- txtBN5.Visible = True
- txtFACID5.Visible = True
- txtMGMT5.Visible = True
- txtCOMMENT5.Visible = True
- txtCITY5.Visible = True
- txtPM5.Visible = True
- txtTYPE5.Visible = True
- txtACTIVITY5.Visible = True
- txtBN4.Visible = True
- txtFACID4.Visible = True
- txtMGMT4.Visible = True
- txtCOMMENT4.Visible = True
- txtCITY4.Visible = True
- txtPM4.Visible = True
- txtTYPE4.Visible = True
- txtACTIVITY4.Visible = True
- txtBN3.Visible = True
- txtFACID3.Visible = True
- txtMGMT3.Visible = True
- txtCOMMENT3.Visible = True
- txtCITY3.Visible = True
- txtPM3.Visible = True
- txtTYPE3.Visible = True
- txtACTIVITY3.Visible = True
- txtBN2.Visible = True
- txtFACID2.Visible = True
- txtMGMT2.Visible = True
- txtCOMMENT2.Visible = True
- txtCITY2.Visible = True
- txtPM2.Visible = True
- txtTYPE2.Visible = True
- txtACTIVITY2.Visible = True
- txtBN1.Visible = True
- txtFACID1.Visible = True
- txtMGMT1.Visible = True
- txtCOMMENT1.Visible = True
- txtCITY1.Visible = True
- txtPM1.Visible = True
- txtTYPE1.Visible = True
- txtACTIVITY1.Visible = True
- End If
- If Entries = 7 Then
- txtBN7.Visible = True
- txtFACID7.Visible = True
- txtMGMT7.Visible = True
- txtCOMMENT7.Visible = True
- txtCITY7.Visible = True
- txtPM7.Visible = True
- txtTYPE7.Visible = True
- txtACTIVITY7.Visible = True
- txtBN6.Visible = True
- txtFACID6.Visible = True
- txtMGMT6.Visible = True
- txtCOMMENT6.Visible = True
- txtCITY6.Visible = True
- txtPM6.Visible = True
- txtTYPE6.Visible = True
- txtACTIVITY6.Visible = True
- txtBN5.Visible = True
- txtFACID5.Visible = True
- txtMGMT5.Visible = True
- txtCOMMENT5.Visible = True
- txtCITY5.Visible = True
- txtPM5.Visible = True
- txtTYPE5.Visible = True
- txtACTIVITY5.Visible = True
- txtBN4.Visible = True
- txtFACID4.Visible = True
- txtMGMT4.Visible = True
- txtCOMMENT4.Visible = True
- txtCITY4.Visible = True
- txtPM4.Visible = True
- txtTYPE4.Visible = True
- txtACTIVITY4.Visible = True
- txtBN3.Visible = True
- txtFACID3.Visible = True
- txtMGMT3.Visible = True
- txtCOMMENT3.Visible = True
- txtCITY3.Visible = True
- txtPM3.Visible = True
- txtTYPE3.Visible = True
- txtACTIVITY3.Visible = True
- txtBN2.Visible = True
- txtFACID2.Visible = True
- txtMGMT2.Visible = True
- txtCOMMENT2.Visible = True
- txtCITY2.Visible = True
- txtPM2.Visible = True
- txtTYPE2.Visible = True
- txtACTIVITY2.Visible = True
- txtBN1.Visible = True
- txtFACID1.Visible = True
- txtMGMT1.Visible = True
- txtCOMMENT1.Visible = True
- txtCITY1.Visible = True
- txtPM1.Visible = True
- txtTYPE1.Visible = True
- txtACTIVITY1.Visible = True
- End If
- txtBN8.Visible = True
- txtFACID8.Visible = True
- txtMGMT8.Visible = True
- txtCOMMENT8.Visible = True
- txtCITY8.Visible = True
- txtPM8.Visible = True
- txtTYPE8.Visible = True
- txtACTIVITY8.Visible = True
- Call DisplayInfo()
- End Sub
- Sub DisplayInfo()
- txtBN1.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 1), 3).Value
- txtFACID1.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 1), 2).Value
- txtMGMT1.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 1), 4).Value
- txtCOMMENT1.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 1), 10).Value
- txtCITY1.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 1), 5).Value
- txtPM1.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 1), 6).Value
- txtTYPE1.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 1), 7).value
- txtACTIVITY1.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 1), 8).value
- txtBN2.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 2), 3).Value
- txtFACID2.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 2), 2).Value
- txtMGMT2.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 2), 4).Value
- txtCOMMENT2.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 2), 10).Value
- txtCITY2.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 2), 5).Value
- txtPM2.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 2), 6).Value
- txtTYPE2.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 2), 7).value
- txtACTIVITY2.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 2), 8).value
- txtBN3.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 3), 3).Value
- txtFACID3.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 3), 2).Value
- txtMGMT3.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 3), 4).Value
- txtCOMMENT3.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 3), 10).Value
- txtCITY3.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 3), 5).Value
- txtPM3.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 3), 6).Value
- txtTYPE3.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 3), 7).value
- txtACTIVITY3.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 3), 8).value
- txtBN4.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 4), 3).Value
- txtFACID4.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 4), 2).Value
- txtMGMT4.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 4), 4).Value
- txtCOMMENT4.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 4), 10).Value
- txtCITY4.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 4), 5).Value
- txtPM4.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 4), 6).Value
- txtTYPE4.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 4), 7).value
- txtACTIVITY4.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 4), 8).value
- txtBN5.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 5), 3).Value
- txtFACID5.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 5), 2).Value
- txtMGMT5.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 5), 4).Value
- txtCOMMENT5.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 5), 10).Value
- txtCITY5.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 5), 5).Value
- txtPM5.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 5), 6).Value
- txtTYPE5.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 5), 7).value
- txtACTIVITY5.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 5), 8).value
- txtBN6.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 6), 3).Value
- txtFACID6.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 6), 2).Value
- txtMGMT6.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 6), 4).Value
- txtCOMMENT6.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 6), 10).Value
- txtCITY6.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 6), 5).Value
- txtPM6.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 6), 6).Value
- txtTYPE6.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 6), 7).value
- txtACTIVITY6.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 6), 8).value
- txtBN7.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 7), 3).Value
- txtFACID7.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 7), 2).Value
- txtMGMT7.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 7), 4).Value
- txtCOMMENT7.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 7), 10).Value
- txtCITY7.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 7), 5).Value
- txtPM7.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 7), 6).Value
- txtTYPE7.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 7), 7).value
- txtACTIVITY7.Text = worksheet.Cells(TotalEntriesTemp - (TotalEntriesTemp - 7), 8).value
- End Sub
- Private Sub Filter1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Filter1.SelectedIndexChanged
- Filter2.Visible = True
- If Filter1.Text = "STATE" Then
- Filter2.Items.Add("AR")
- Filter2.Items.Add("AZ")
- Filter2.Items.Add("CO")
- Filter2.Items.Add("FL")
- Filter2.Items.Add("LA")
- Filter2.Items.Add("GA")
- Filter2.Items.Add("NC")
- Filter2.Items.Add("SC")
- Filter2.Items.Add("OR")
- Filter2.Items.Add("TN")
- Filter2.Items.Add("TX")
- Filter2.Items.Add("WA")
- End If
- End Sub
- Private Sub Filter2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Filter2.SelectedIndexChanged
- btnLoad.Visible = True
- End Sub
- Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
- worksheet.Cells(1, 3).Value = txtBN1.Text
- worksheet.Cells(1, 2).Value = txtFACID1.Text
- worksheet.Cells(1, 4).Value = txtMGMT1.Text
- worksheet.Cells(1, 10).value = txtCOMMENT1.Text
- workbook.Save()
- workbook.Close()
- End Sub
- Private Sub Form1_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
- APP.Quit()
- End Sub
- Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
- If TotalEntriesTemp > Entries Then
- TotalEntriesTemp = TotalEntriesTemp - (TotalEntriesTemp - Entries)
- Else
- TotalEntriesTemp = Entries
- End If
- Call DisplayInfo()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment