Excel VBA: How to push data to an exclusive range on another sheet?

JohnstownFlood

I use the sub below as part of another sub which error checks and saves a grade sheet. There will be at least 39 grade sheets generated throughout the course this is built for. Each event may be accomplished more than once - a weather cancel, or student failed.

The FindEmptyInsertData sub takes the three most important data from a grade sheet (Date, Grade, Status) and adds them to a sheet named Index. Index then keeps a running tally on the events accomplished...based solely on the output of the 'Error Check and Save' macro.

My question is more of a logic question, rather than for specific code (although it'll help). FindEmptyInsertData works wonderfully. However, the data gets pushed and added to Index however many times the user clicks the 'Error Check and Save' Form Control button. I would like it to only get pushed once per grade sheet...the problem/challenge is that a user might need to go back and change the grade sheet (wrong date, different status...etc).

Index looks like this:

    Event   ABC-1   ABC-2   DEF-1   DEF-2
    Date    dd-mmm  dd-mmm  dd-mmm  dd-mmm
    Grade     1        2      2       3
    Status    WX      EFF    EFF     EFF
            ----    ----    ----    ----
    Date    dd-mmm
    Grade     3
    Status   EFF

I'm thinking that my solution will lie in the fact that only one event will ever be attempted/accomplished per day. Therefore...if date of gradesheet matches the date in index, then don't push the data again...except if the grade or status changes. Ugh, my brain hurts!

Thanks in advance!

Sub FindEmptyInsertData()

Dim ws As Worksheet
Dim gsDate As Date
Dim gsWorking As String
Dim gsMsnNum As String
Dim colNum As Integer

gsWorking = ActiveWindow.ActiveSheet.Name
gsDate = ActiveSheet.Range("S3")
gsGrade = ActiveSheet.Range("D40")
gsStatus = ActiveSheet.Range("O7")
gsMsnNum = ActiveSheet.Range("D3")

Application.ScreenUpdating = False


    'Opens up the INDEX (Sheet4) and finds the first empty cell
        Sheet4.Activate
        Sheet4.Unprotect

    'Finds the sortie name column in INDEX
        For Each Cell In ActiveSheet.Rows(5).Cells
        If Cell = gsMsnNum Then Cell.Select: Exit For
        Next Cell

    'Takes the active column number and assigns it to the variable
        colNum = ActiveCell.Column

    'Finds the first open cell in that column
        For Each Cell In ActiveSheet.Columns(colNum).Cells
        If Len(Cell) = 0 Then Cell.Select: Exit For
        Next Cell

    ActiveCell.Value = gsDate 'Prints the Date from the GS into the first empty cell
    ActiveCell.NumberFormat = "dd-mmm"

        Selection.Offset(1, 0).Select 'Moves One Cell Down

    ActiveCell.Value = gsGrade 'Prints the Grade from the GS

        Selection.Offset(1, 0).Select 'Moves One Cell Down

    ActiveCell.Value = gsStatus 'Prints the Status from the GS
    ActiveCell.Borders(xlEdgeBottom).Weight = xlMedium 'Adds a bottom border

    'Protects the Index Page
    Sheet4.Protect



    'Returns to the Previously open GS
    Worksheets(gsWorking).Activate


End Sub
Archias

Without seeing your Index and other code involved, this is the best recommendation I could make.

Conceptually, as far as simple database design goes, you might benefit from adding a 5th row for Event Sequence. Add an integer variable to your code that looks for the sequence and when assigning data for an event. Increment it by 1 when adding event data to the index. If you hate the idea of consuming an entire row you can also tell your code to hide the row.

This way you can have as many entries containing same or different data as necessary. You can choose to accept the "Event" and highest number for "Sequence" as the final submitted grade by default.

Event   ABC-1   ABC-2   DEF-1   DEF-2
-------------------------------------
Seq       1        1      1       1    ' <--- Pull data by Event Name & Sequence
Date    dd-mmm  dd-mmm  dd-mmm  dd-mmm
Grade     1        2      2       3
Status    WX      EFF    EFF     EFF
         ----    ----    ----    ----
Seq       2                            ' <--- Pull data by Event Name & Sequence
Date    dd-mmm
Grade     3
Status   EFF

Additionally, you could add another row to the Index that would contain data for which event is the active one that you have pushed to the grade sheet.

Event   ABC-1   ABC-2   DEF-1   DEF-2
-------------------------------------
Seq       1        1      1       1   ' <--- Pull data by Event Name & Sequence
Date    dd-mmm  dd-mmm  dd-mmm  dd-mmm
Grade     1        2      2       3
Status    WX      EFF    EFF     EFF
Active    0        1      1       1
         ----    ----    ----    ----
Seq       2                            ' <--- Pull data by Event Name & Sequence
Date    dd-mmm
Grade     3
Status   EFF
Active    1

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Excel VBA: How to push data to an exclusive range on another sheet?

From Dev

Excel VBA, How to use the selection in a dropdown list on one sheet format(color) a range of cells on another sheet

From Dev

Excel VBA 2016 Passing range cells to another sheet as calculated

From Dev

How to Copy Range of Filtered Data and Paste it to new work sheet in Excel VBA (without Using Clipboard)

From Dev

excel vba: copy rows if data match with values in column in another sheet

From Dev

Renaming sheet in Excel with reference to another sheet, VBA

From Dev

VBA Excel: How to assign range of cells to another range of cells?

From Dev

How to read data from Excel Sheet using Excel VBA 2010

From Dev

How to filter the table and paste the value in another sheet in Excel VBA

From Dev

How to use each value in a range to autofilter data in another sheet?

From Dev

How to replace autofill range based on data in another sheet

From Dev

VBA: Unable to reference Range in another sheet

From Dev

VBA Copy range values and paste in another sheet

From Dev

Excel VBA select entire sheet using Range

From Dev

Excel VBA select entire sheet using Range

From Dev

Reference cell range on another sheet - Excel

From Dev

Excel vba find text in sheet, copy range, paste to other sheet

From Dev

How do I copy data from one excel sheet to another excel sheet?

From Dev

excel vba copy data range, open new xlsx file rename sheet and save

From Dev

Excel VBA copy data in a range for every 100000 rows and paste to a different sheet until all the data has been copied in the range

From Dev

Excel VBA copying a static range into a dynamic range on different sheet

From Dev

Need to copy range of data from one excel sheet to another based on first coulmn value

From Dev

Excel: change VBA action frome same sheet to another sheet

From Dev

Extracting data from an excel sheet into another excel sheet

From Dev

How to keep history of data changes in one excel workbook or sheet to another workbook or sheet

From Dev

Excel - How to pull data from a sheet and list/count on another sheet by date?

From Dev

Copy filtered data to another sheet using VBA

From Dev

VBA Copy data from one sheet to another

From Dev

VBA: Copying Segments of data onto another sheet

Related Related

  1. 1

    Excel VBA: How to push data to an exclusive range on another sheet?

  2. 2

    Excel VBA, How to use the selection in a dropdown list on one sheet format(color) a range of cells on another sheet

  3. 3

    Excel VBA 2016 Passing range cells to another sheet as calculated

  4. 4

    How to Copy Range of Filtered Data and Paste it to new work sheet in Excel VBA (without Using Clipboard)

  5. 5

    excel vba: copy rows if data match with values in column in another sheet

  6. 6

    Renaming sheet in Excel with reference to another sheet, VBA

  7. 7

    VBA Excel: How to assign range of cells to another range of cells?

  8. 8

    How to read data from Excel Sheet using Excel VBA 2010

  9. 9

    How to filter the table and paste the value in another sheet in Excel VBA

  10. 10

    How to use each value in a range to autofilter data in another sheet?

  11. 11

    How to replace autofill range based on data in another sheet

  12. 12

    VBA: Unable to reference Range in another sheet

  13. 13

    VBA Copy range values and paste in another sheet

  14. 14

    Excel VBA select entire sheet using Range

  15. 15

    Excel VBA select entire sheet using Range

  16. 16

    Reference cell range on another sheet - Excel

  17. 17

    Excel vba find text in sheet, copy range, paste to other sheet

  18. 18

    How do I copy data from one excel sheet to another excel sheet?

  19. 19

    excel vba copy data range, open new xlsx file rename sheet and save

  20. 20

    Excel VBA copy data in a range for every 100000 rows and paste to a different sheet until all the data has been copied in the range

  21. 21

    Excel VBA copying a static range into a dynamic range on different sheet

  22. 22

    Need to copy range of data from one excel sheet to another based on first coulmn value

  23. 23

    Excel: change VBA action frome same sheet to another sheet

  24. 24

    Extracting data from an excel sheet into another excel sheet

  25. 25

    How to keep history of data changes in one excel workbook or sheet to another workbook or sheet

  26. 26

    Excel - How to pull data from a sheet and list/count on another sheet by date?

  27. 27

    Copy filtered data to another sheet using VBA

  28. 28

    VBA Copy data from one sheet to another

  29. 29

    VBA: Copying Segments of data onto another sheet

HotTag

Archive