bhsoundman
Board Regular
- Joined
- Jul 17, 2010
- Messages
- 50
- Office Version
- 365
- Platform
- MacOS
Hi All,
I've pieced together this code & although the end result is exactly what I need it to do, I'm sure it's not nearly efficient or fast enough.
The basic set up is some data in column G1:AB24. Each row represents a person & the next 20 columns in that row may or may not have times. If there's a blank row in column G (no name) then that row is skipped entirely.
The version of the data without blank rows gets put into AD1:AX24.
A loop within a loop basically.
Can someone help me streamline this code? Thanks so much!
I've pieced together this code & although the end result is exactly what I need it to do, I'm sure it's not nearly efficient or fast enough.
The basic set up is some data in column G1:AB24. Each row represents a person & the next 20 columns in that row may or may not have times. If there's a blank row in column G (no name) then that row is skipped entirely.
The version of the data without blank rows gets put into AD1:AX24.
A loop within a loop basically.
Can someone help me streamline this code? Thanks so much!
VBA Code:
Sub copy_times()
'
Range("g1").Select
Dim RowCount As Long
Dim ColCount As Long
Dim tmpstr As String
Dim PrevCell As Range
Dim Time1 As String
Dim Time2 As String
Dim Time3 As String
Dim Time4 As String
Dim Time5 As String
Dim Time6 As String
Dim Time7 As String
Dim Time8 As String
Dim Time9 As String
Dim Time10 As String
Dim Time11 As String
Dim Time12 As String
Dim Time13 As String
Dim Time14 As String
Dim Time15 As String
Dim Time16 As String
Dim Time17 As String
Dim Time18 As String
Dim Time19 As String
Dim Time20 As String
Set PrevCell = ActiveCell
For RowCount = 1 To 25
tmpstr = ""
Time1 = ""
For ColCount = 7 To 7
tmpstr = tmpstr & Cells(RowCount, ColCount)
Time1 = Cells(RowCount, ColCount).Offset(0, 1)
Time2 = Cells(RowCount, ColCount).Offset(0, 2)
Time3 = Cells(RowCount, ColCount).Offset(0, 3)
Time4 = Cells(RowCount, ColCount).Offset(0, 4)
Time5 = Cells(RowCount, ColCount).Offset(0, 5)
Time6 = Cells(RowCount, ColCount).Offset(0, 6)
Time7 = Cells(RowCount, ColCount).Offset(0, 7)
Time8 = Cells(RowCount, ColCount).Offset(0, 8)
Time9 = Cells(RowCount, ColCount).Offset(0, 9)
Time10 = Cells(RowCount, ColCount).Offset(0, 10)
Time11 = Cells(RowCount, ColCount).Offset(0, 11)
Time12 = Cells(RowCount, ColCount).Offset(0, 12)
Time13 = Cells(RowCount, ColCount).Offset(0, 13)
Time14 = Cells(RowCount, ColCount).Offset(0, 14)
Time15 = Cells(RowCount, ColCount).Offset(0, 15)
Time16 = Cells(RowCount, ColCount).Offset(0, 16)
Time17 = Cells(RowCount, ColCount).Offset(0, 17)
Time18 = Cells(RowCount, ColCount).Offset(0, 18)
Time19 = Cells(RowCount, ColCount).Offset(0, 19)
Time20 = Cells(RowCount, ColCount).Offset(0, 20)
Next ColCount
If tmpstr <> "" Then
Range("ad1").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell.Select
ActiveCell = tmpstr
ActiveCell.Offset(0, 1) = Time1
ActiveCell.Offset(0, 2) = Time2
ActiveCell.Offset(0, 3) = Time3
ActiveCell.Offset(0, 4) = Time4
ActiveCell.Offset(0, 5) = Time5
ActiveCell.Offset(0, 6) = Time6
ActiveCell.Offset(0, 7) = Time7
ActiveCell.Offset(0, 8) = Time8
ActiveCell.Offset(0, 9) = Time9
ActiveCell.Offset(0, 10) = Time10
ActiveCell.Offset(0, 11) = Time11
ActiveCell.Offset(0, 12) = Time12
ActiveCell.Offset(0, 13) = Time13
ActiveCell.Offset(0, 14) = Time14
ActiveCell.Offset(0, 15) = Time15
ActiveCell.Offset(0, 16) = Time16
ActiveCell.Offset(0, 17) = Time17
ActiveCell.Offset(0, 18) = Time18
ActiveCell.Offset(0, 19) = Time19
ActiveCell.Offset(0, 20) = Time20
PrevCell.Select
Application.CutCopyMode = False
End If
Next RowCount
End Sub
Last edited by a moderator: