Hello!
I just starting learning VBA to solve this problem. I have data that I need to interpret, but the way it is outputted makes it impossible. I figured out how to use VBA to solve it using this forum, but I am aware it is done about as clunkily as possible (i.e. I use a ton of 'Select' commands and have tons of data on the clipboard). I tried doing it more streamlined, but hit a wall in what I have been able to self-teach. I would love help streamlining what I have done.
I have 500ish lines of data. Each new data set starts at '9999'. The end goal is to find the average of each data set and make a graph. I approached it by getting each row to start with '9999' and then I can do the averaging/graphing easily after that. (I have not created an averaging or graphing macro yet, just the organizing the data.) The way I could figure it out was to get all data onto one long row, then copy the data starting at the next '9999' cell down a row and loop until all of Column A is '9999', with the data after it.
Here is an example of what the data output looks like before running the macro:
Here is the code I am using:
I really appreciate any guidance you have! I worry it may crash on large data sets, but it seems to be functioning OK. It just bogs everything down. Thank you in advance!
I just starting learning VBA to solve this problem. I have data that I need to interpret, but the way it is outputted makes it impossible. I figured out how to use VBA to solve it using this forum, but I am aware it is done about as clunkily as possible (i.e. I use a ton of 'Select' commands and have tons of data on the clipboard). I tried doing it more streamlined, but hit a wall in what I have been able to self-teach. I would love help streamlining what I have done.
I have 500ish lines of data. Each new data set starts at '9999'. The end goal is to find the average of each data set and make a graph. I approached it by getting each row to start with '9999' and then I can do the averaging/graphing easily after that. (I have not created an averaging or graphing macro yet, just the organizing the data.) The way I could figure it out was to get all data onto one long row, then copy the data starting at the next '9999' cell down a row and loop until all of Column A is '9999', with the data after it.
Here is an example of what the data output looks like before running the macro:
Hannah's Excel Copy.xlsm | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | |||
1 | Address | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ||
2 | DS631 | 36 | 36 | 36 | 37 | 36 | 37 | 31 | 8 | 9999 | 0 | ||
3 | DS641 | 32 | 41 | 40 | 41 | 41 | 42 | 42 | 43 | 43 | 44 | ||
4 | DS651 | 44 | 44 | 45 | 45 | 45 | 40 | 10 | 9999 | 0 | 33 | ||
5 | DS661 | 37 | 36 | 37 | 37 | 37 | 37 | 37 | 37 | 36 | 36 | ||
6 | DS671 | 37 | 37 | 37 | 37 | 37 | 27 | 10 | 9999 | 0 | 34 | ||
7 | DS681 | 20 | 36 | 39 | 38 | 39 | 39 | 40 | 41 | 42 | 42 | ||
8 | DS691 | 43 | 42 | 42 | 43 | 43 | 41 | 10 | 9999 | 0 | 35 | ||
9 | DS701 | 34 | 38 | 38 | 38 | 39 | 38 | 38 | 39 | 38 | 38 | ||
10 | DS711 | 38 | 38 | 38 | 38 | 39 | 34 | 7 | 9999 | 0 | 36 | ||
11 | DS721 | 41 | 39 | 40 | 40 | 40 | 40 | 40 | 40 | 41 | 42 | ||
12 | DS731 | 42 | 42 | 42 | 43 | 43 | 42 | 9 | 9999 | 0 | 37 | ||
13 | DS741 | 20 | 38 | 37 | 38 | 38 | 38 | 38 | 39 | 39 | 38 | ||
14 | DS751 | 38 | 39 | 38 | 39 | 39 | 38 | 11 | 11 | 9999 | 0 | ||
15 | DS761 | 38 | 37 | 39 | 39 | 40 | 39 | 39 | 39 | 40 | 41 | ||
16 | DS771 | 41 | 41 | 41 | 42 | 43 | 43 | 42 | 9 | 9999 | 0 | ||
17 | DS781 | 39 | 35 | 36 | 36 | 36 | 36 | 36 | 38 | 37 | 36 | ||
18 | DS791 | 37 | 37 | 36 | 37 | 37 | 37 | 33 | 9 | 9999 | 0 | ||
19 | DS801 | 40 | 42 | 41 | 41 | 42 | 43 | 41 | 42 | 43 | 43 | ||
20 | DS811 | 44 | 44 | 44 | 45 | 46 | 46 | 35 | 32 | 9999 | 0 | ||
21 | DS821 | 41 | 37 | 37 | 36 | 36 | 36 | 37 | 37 | 36 | 36 | ||
22 | DS831 | 36 | 36 | 36 | 36 | 36 | 32 | 11 | 9999 | 0 | 42 | ||
23 | DS841 | 34 | 41 | 40 | 40 | 41 | 40 | 42 | 42 | 42 | 43 | ||
24 | DS851 | 43 | 44 | 44 | 45 | 46 | 38 | 13 | 9999 | 0 | 43 | ||
25 | DS861 | 37 | 37 | 37 | 37 | 37 | 37 | 37 | 37 | 37 | 37 | ||
26 | DS871 | 36 | 37 | 37 | 37 | 31 | 10 | 9999 | 0 | 44 | 36 | ||
27 | DS881 | 41 | 39 | 39 | 41 | 40 | 41 | 41 | 42 | 41 | 42 | ||
28 | DS891 | 42 | 43 | 43 | 44 | 36 | 12 | 9999 | 0 | 45 | 34 | ||
29 | DS901 | 37 | 37 | 38 | 37 | 37 | 37 | 37 | 37 | 37 | 37 | ||
Sheet2 |
Here is the code I am using:
VBA Code:
Sub OrganizeData()
' Deletes Header Row
' Deletes Header Column
' Copies Range A2:J2
' Pastes first open cell Row 1
' Deletes Emptry Row 2
' Repeates until no data is left
' Search each row for first instance of 9999 after A2
' Copy data from that cell to end of line
' Paste data on next row
' Repeat until all data is sorted
Rows(1).EntireRow.Delete
Columns(1).EntireColumn.Delete
Do Until IsEmpty("A2:J2")
Range("A2:J2").Select
Selection.Cut
Range("A1").Select
Selection.End(xlToRight).Select
ActiveCell.Offset(0, 1).Select
ActiveSheet.Paste
Rows("2:2").Select
Selection.Delete Shift:=xlUp
If IsEmpty(ActiveCell) Then
Exit Do
End If
Loop
Range("A1").Select
Do While ActiveCell >= 0
If ActiveCell >= 0 Then
ActiveCell.End(xlToLeft).Select
ActiveCell.Offset(0, 1).Select
Do Until ActiveCell = 9999
If ActiveCell = 9999 Then
Else
ActiveCell.Offset(0, 1).Select
End If
If (IsEmpty(ActiveCell)) Then Exit Do
Loop
Range(ActiveCell, ActiveCell.End(xlToRight)).Select
Selection.Cut
ActiveCell.End(xlToLeft).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Else
End If
If (IsEmpty(ActiveCell)) Then Exit Do
Loop
End Sub
I really appreciate any guidance you have! I worry it may crash on large data sets, but it seems to be functioning OK. It just bogs everything down. Thank you in advance!