I am attempting to do the following:
Look at the first row's column B (Event) from entiresalespipeline
Match Column B to a table (Events_and_Activities) that links a date to each event
If that date is in the future, copy the entire row into the next empty row in a third worksheet (CurrentSalesPipeline)
Repeat this process until there are no more filled rows in the first spreadsheet.
I have created the following code, which when I mouse-over the text appears to give correct data, but which gives me the following error:
Run-time error '13': Type mismatch
Sub ShowUpcoming_Click()
Dim rCell As Range
Dim ws As Worksheet
Dim DateConf As Long
For Each rCell In Sheet1.Range("B3:B5000")
Set ws = Worksheets("CurrentSalesPipeline")
DateConf = Application.VLookup(rCell, Worksheets("Events_and_Activities").Range("A2:B12"), 2, False)
Range("A1").Value = DateConf
If CDate(DateConf) >= CDate((Date)) Then
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
With ws
.Cells(iRow, 1).Value = Worksheets("entiresalespipeline").Range("A3:A3").Value
.Cells(iRow, 2).Value = Worksheets("entiresalespipeline").Range("B3:B3").Value
.Cells(iRow, 3).Value = Worksheets("entiresalespipeline").Range("C3:C3").Value
.Cells(iRow, 4).Value = Worksheets("entiresalespipeline").Range("D3:D3").Value
.Cells(iRow, 5).Value = Worksheets("entiresalespipeline").Range("E3:E3").Value
.Cells(iRow, 6).Value = Worksheets("entiresalespipeline").Range("F3:F3").Value
.Cells(iRow, 7).Value = Worksheets("entiresalespipeline").Range("G3:G3").Value
.Cells(iRow, 8).Value = Worksheets("entiresalespipeline").Range("H3:H3").Value
.Cells(iRow, 9).Value = Worksheets("entiresalespipeline").Range("I3:I3").Value
.Cells(iRow, 10).Value = Worksheets("entiresalespipeline").Range("J3:J3").Value
.Cells(iRow, 11).Value = Worksheets("entiresalespipeline").Range("K3:K3").Value
.Cells(iRow, 12).Value = Worksheets("entiresalespipeline").Range("L3:L3").Value
.Cells(iRow, 13).Value = Worksheets("entiresalespipeline").Range("M3:M3").Value
.Cells(iRow, 14).Value = Worksheets("entiresalespipeline").Range("N3:N3").Value
.Cells(iRow, 15).Value = Worksheets("entiresalespipeline").Range("O3:O3").Value
.Cells(iRow, 16).Value = Worksheets("entiresalespipeline").Range("P3:P3").Value
.Cells(iRow, 17).Value = Worksheets("entiresalespipeline").Range("Q3:Q3").Value
.Cells(iRow, 18).Value = Worksheets("entiresalespipeline").Range("R3:R3").Value
.Cells(iRow, 19).Value = Worksheets("entiresalespipeline").Range("S3:S3").Value
.Cells(iRow, 20).Value = Worksheets("entiresalespipeline").Range("T3:T3").Value
End With
End If
Next rCell
End Sub
You're declaring DateConf as a Long:
Dim DateConf As Long
And then assigning it the result of the VLookup call:
DateConf = Application.VLookup(rCell, Worksheets("Events_and_Activities").Range("A2:B12"), 2, False)
That's a lot of assumptions to make: you're relying on VBA to perform an implicit conversion of the returned value to a Long, without knowing if the returned value will be a valid numeric.
What if the VLookup returns an empty string? What if it returned an #N/A error value?
Dim lookupResult As Variant
lookupResult = Application.VLookup(rCell, Worksheets("Events_and_Activities").Range("A2:B12"), 2, False)
If IsNumeric(lookupResult) Then
DateConf = CLng(lookupResult)
...
End If
Reduce the number of assumptions you're making, you'll reduce the number of potential issues by as much.
Thank you everyone for your very thoughtful and extremely helpful input!
After some tinkering, I managed to come up with the following, which does everything I need it to do.
Mat's Mug - your suggestion was perfect!
Tim Williams - I tried your single line solution to the copy/pasting, but it only copied the first line (headings) over every line in the range, so I stuck with what I had.
Sub ShowUpcoming_Click()
Dim lastrow As Long
Dim ws As Worksheet
Dim DateConf As Long
Dim r As Long
Set ws = Worksheets("CurrentSalesPipeline")
Dim lookupresult As Variant
'find last completed row of entire spreadsheet
lastrow = Worksheets("EntireSalesPipeline").Range("B" & Rows.Count).End(xlUp).Row
'From the first completed line (row 3) to last completed row
For r = 3 To lastrow
'lookup conference date from events/activities spreadsheet
lookupresult = Application.VLookup(Worksheets("EntireSalesPipeline").Cells(r, 2).Value, Worksheets("Events_and_activities").Range("A2:B13"), 2, False)
If IsNumeric(lookupresult) Then
DateConf = CLng(lookupresult)
End If
'If vlookup finds a date, then check to make sure it is in the future from when the button was hit.
If CDate(DateConf) >= CDate((Date)) Then
'If it is a future event, then copy that data into the current spreadsheet
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
With ws
.Cells(iRow, 1).Value = Worksheets("entiresalespipeline").Cells(r, 1).Value
.Cells(iRow, 2).Value = Worksheets("entiresalespipeline").Cells(r, 2).Value
.Cells(iRow, 3).Value = Worksheets("entiresalespipeline").Cells(r, 3).Value
.Cells(iRow, 4).Value = Worksheets("entiresalespipeline").Cells(r, 4).Value
.Cells(iRow, 5).Value = Worksheets("entiresalespipeline").Cells(r, 5).Value
.Cells(iRow, 6).Value = Worksheets("entiresalespipeline").Cells(r, 6).Value
.Cells(iRow, 7).Value = Worksheets("entiresalespipeline").Cells(r, 7).Value
.Cells(iRow, 8).Value = Worksheets("entiresalespipeline").Cells(r, 8).Value
.Cells(iRow, 9).Value = Worksheets("entiresalespipeline").Cells(r, 9).Value
.Cells(iRow, 10).Value = Worksheets("entiresalespipeline").Cells(r, 10).Value
.Cells(iRow, 11).Value = Worksheets("entiresalespipeline").Cells(r, 11).Value
.Cells(iRow, 12).Value = Worksheets("entiresalespipeline").Cells(r, 12).Value
.Cells(iRow, 13).Value = Worksheets("entiresalespipeline").Cells(r, 13).Value
.Cells(iRow, 14).Value = Worksheets("entiresalespipeline").Cells(r, 14).Value
.Cells(iRow, 15).Value = Worksheets("entiresalespipeline").Cells(r, 15).Value
.Cells(iRow, 16).Value = Worksheets("entiresalespipeline").Cells(r, 16).Value
.Cells(iRow, 17).Value = Worksheets("entiresalespipeline").Cells(r, 17).Value
.Cells(iRow, 18).Value = Worksheets("entiresalespipeline").Cells(r, 18).Value
.Cells(iRow, 19).Value = Worksheets("entiresalespipeline").Cells(r, 19).Value
.Cells(iRow, 20).Value = Worksheets("entiresalespipeline").Cells(r, 20).Value
End With
End If
'Repeat for next line in existing
Next r
End Sub
This is a great community. Thank you again!
Sarah
Related
Need help to add the code correctly for userform progress bar.
For Each cel In rList
Set fnd = ThisWorkbook.Worksheets("Database").Columns("A:A").Find(What:=cel.Value, LookAt:=xlWhole)
If Not fnd Is Nothing Then
fndFirst = fnd.Address
Do
fnd.Offset(0, 4).Value = cel.Offset(0, 4).Value
fnd.Offset(0, 5).Value = cel.Offset(0, 5).Value
fnd.Offset(0, 6).Value = cel.Offset(0, 6).Value
fnd.Offset(0, 7).Value = cel.Offset(0, 7).Value
fnd.Offset(0, 8).Value = cel.Offset(0, 8).Value
fnd.Offset(0, 9).Value = cel.Offset(0, 9).Value
fnd.Offset(0, 10).Value = cel.Offset(0, 10).Value
Set fnd = ThisWorkbook.Worksheets("Database").Columns("A:A").FindNext(After:=fnd)
Loop While fnd.Address <> fndFirst
End If
Next
Any help is highly appreciated. Thanks!
I have two hardware devices that record data and I need to sync the times recorded by each so the data matches on both devices.
The times are close but not always identical: I record data every 0.2 seconds, but sometimes one device will have a slightly larger or smaller gap.
Currently, I import the times from L unit and R unit into excel, then round the times to the nearest 0.1 sec. That way, the times either match exactly or are off by 0.1 sec (which is close enough for my purposes).
I wrote a VBA script (below) to paste the data from the R unit into the L unit. It works fine, but it is too slow for the amount of data I am dealing with (25,000+ rows)
I hoping someone can examine the code and suggest a faster way to do the same thing.
Sub NewTimesComparisonLoop()
Application.ScreenUpdating = False
Dim LBottomRow As Long
Dim RBottomRow As Long
Dim LSheet As Worksheet
Dim Rsheet As Worksheet
Dim LStartCell As Range
Dim RStartcell As Range
Dim Li As Long
Dim Ri As Long
Set LSheet = Worksheets("Sheet1")
Set Rsheet = Worksheets("Sheet2")
'find the last row of times in column b
Set LStartCell = Range("B1")
LBottomRow = LSheet.Cells(LSheet.Rows.Count, LStartCell.Column).End(xlUp).row
Set RStartcell = Range("B1")
RBottomRow = Rsheet.Cells(Rsheet.Rows.Count, RStartcell.Column).End(xlUp).row
'get data set of sheet1, column B
'LSheet.Range(StartCell, LSheet.Cells(BottomRow, 2)).Select
'loop through each R value, comparing against a loop of L values
'if they match, or if R is under by 0.1 sec, copy the R values into columns j through P
For Ri = 1 To RBottomRow
For Li = 1 To LBottomRow
If Sheets("Sheet2").Cells(Ri, 2).Value = Sheets("Sheet1").Cells(Li, 2).Value Then
Sheets("Sheet1").Cells(Li, 10).Value = Sheets("Sheet2").Cells(Ri, 3).Value
Sheets("Sheet1").Cells(Li, 11).Value = Sheets("Sheet2").Cells(Ri, 4).Value
Sheets("Sheet1").Cells(Li, 12).Value = Sheets("Sheet2").Cells(Ri, 5).Value
Sheets("Sheet1").Cells(Li, 13).Value = Sheets("Sheet2").Cells(Ri, 6).Value
Sheets("Sheet1").Cells(Li, 14).Value = Sheets("Sheet2").Cells(Ri, 7).Value
Sheets("Sheet1").Cells(Li, 15).Value = Sheets("Sheet2").Cells(Ri, 8).Value
Sheets("Sheet1").Cells(Li, 16).Value = Sheets("Sheet2").Cells(Ri, 9).Value
ElseIf Sheets("Sheet2").Cells(Ri, 2).Value + 0.1 = Sheets("Sheet1").Cells(Li, 2).Value Then
Sheets("Sheet1").Cells(Li, 10).Value = Sheets("Sheet2").Cells(Ri, 3).Value
Sheets("Sheet1").Cells(Li, 11).Value = Sheets("Sheet2").Cells(Ri, 4).Value
Sheets("Sheet1").Cells(Li, 12).Value = Sheets("Sheet2").Cells(Ri, 5).Value
Sheets("Sheet1").Cells(Li, 13).Value = Sheets("Sheet2").Cells(Ri, 6).Value
Sheets("Sheet1").Cells(Li, 14).Value = Sheets("Sheet2").Cells(Ri, 7).Value
Sheets("Sheet1").Cells(Li, 15).Value = Sheets("Sheet2").Cells(Ri, 8).Value
Sheets("Sheet1").Cells(Li, 16).Value = Sheets("Sheet2").Cells(Ri, 9).Value
End If
Next Li
Next Ri
Application.ScreenUpdating = True
End Sub
Use a collection when matching values. Here I use a Scripting.Dictionary.
Sub NewTimesComparisonLoop()
Application.ScreenUpdating = False
Dim cell As Range, dict As Object
Set dict = CreateObject("Scripting.Dictionary")
With Sheets("Sheet2")
For Each cell In .Range("B1", .Range("B" & .Rows.Count).End(xlUp))
If Not dict.Exists(cell.Value) Then dict.Add cell.Value, cell.Offset(0, 1).Resize(1, 7).Value
Next
End With
With Sheets("Sheet1")
For Each cell In .Range("B1", .Range("B" & .Rows.Count).End(xlUp))
If dict.Exists(cell.Value) Then
cell.Offset(0, 1).Resize(1, 7).Value = dict(cell.Value)
ElseIf dict.Exists(cell.Value + 0.1) Then
cell.Offset(0, 1).Resize(1, 7).Value = dict(cell.Value + 0.1)
End If
Next
End With
Application.ScreenUpdating = True
End Sub
Technically, this type of post belongs in CodeReview.SE.
But I don't know how to vote to migrate it there, so here's what should be a significantly smaller code... how it compares in regards to execution time is a little up in the air, but it ought to be faster as well.
Replace this:
For Ri = 1 To RBottomRow
For Li = 1 To LBottomRow
If Sheets("Sheet2").Cells(Ri, 2).Value = Sheets("Sheet1").Cells(Li, 2).Value Then
Sheets("Sheet1").Cells(Li, 10).Value = Sheets("Sheet2").Cells(Ri, 3).Value
Sheets("Sheet1").Cells(Li, 11).Value = Sheets("Sheet2").Cells(Ri, 4).Value
Sheets("Sheet1").Cells(Li, 12).Value = Sheets("Sheet2").Cells(Ri, 5).Value
Sheets("Sheet1").Cells(Li, 13).Value = Sheets("Sheet2").Cells(Ri, 6).Value
Sheets("Sheet1").Cells(Li, 14).Value = Sheets("Sheet2").Cells(Ri, 7).Value
Sheets("Sheet1").Cells(Li, 15).Value = Sheets("Sheet2").Cells(Ri, 8).Value
Sheets("Sheet1").Cells(Li, 16).Value = Sheets("Sheet2").Cells(Ri, 9).Value
ElseIf Sheets("Sheet2").Cells(Ri, 2).Value + 0.1 = Sheets("Sheet1").Cells(Li, 2).Value Then
Sheets("Sheet1").Cells(Li, 10).Value = Sheets("Sheet2").Cells(Ri, 3).Value
Sheets("Sheet1").Cells(Li, 11).Value = Sheets("Sheet2").Cells(Ri, 4).Value
Sheets("Sheet1").Cells(Li, 12).Value = Sheets("Sheet2").Cells(Ri, 5).Value
Sheets("Sheet1").Cells(Li, 13).Value = Sheets("Sheet2").Cells(Ri, 6).Value
Sheets("Sheet1").Cells(Li, 14).Value = Sheets("Sheet2").Cells(Ri, 7).Value
Sheets("Sheet1").Cells(Li, 15).Value = Sheets("Sheet2").Cells(Ri, 8).Value
Sheets("Sheet1").Cells(Li, 16).Value = Sheets("Sheet2").Cells(Ri, 9).Value
End If
Next Li
Next Ri
With this:
For Ri = 1 To RBottomRow
For Li = 1 To LBottomRow
If ("Sheet2").Cells(Ri, 2).Value - Sheets("Sheet1").Cells(Li, 2).Value <= 0.1 Then _
Sheets("Sheet1").Range("J" & Li & ":P" & Li).Value = _
("Sheet2").Range("C" & Ri & ":I" & Ri).Value
Next Li
Next Ri
I have three sheets, sheet S, Sheet P and Sheet Data.
I first copy the column of Sheet S to Sheet Data. Then in column E of sheet Data, I look for the ID. The ID In column E of data sheet, matches with the column A of P sheet, then I copy the corresponding ID.
The problem here is the Sheet data contains 214 rows, while sheet P contains 1110.
while comparing the ID, there are two different ID from row 870 and 871, which are not copied, even though they are same.
Could someone guide what could be the reason ?
Sub lookup()
Dim lLastrow, totalrows As Long
Dim rng As Range
Dim i As Long
'Copy lookup values from S to Data
With Sheets("S")
lLastrow = .Cells(.Rows.count, 1).End(xlUp).Row
.Range("P5:P" & lLastrow).Copy Destination:=Sheets("Data").Range("E5")
.Range("G5:G" & lLastrow).Copy Destination:=Sheets("Data").Range("H5")
End With
totalrows = Sheets("P").Cells(Sheets("P").Rows.count, "A").End(xlUp).Row
For i = 5 To lLastrow
'Search for the value on P_APQP
With Sheets("P")
Set rng = .Columns(1).Find(Sheets("Data").Cells(i, 5).Value & "*", lookat:=xlWhole)
End With
'If it is found put its value on the destination sheet
If Not rng Is Nothing Then
With Sheets("Data")
.Cells(i, 6).Value = rng.Value
.Cells(i, 1).Value = rng.Offset(0, 1).Value
.Cells(i, 2).Value = rng.Offset(0, 2).Value
.Cells(i, 3).Value = rng.Offset(0, 3).Value
.Cells(i, 4).Value = rng.Offset(0, 9).Value
.Cells(i, 9).Value = rng.Offset(0, 10).Value
.Cells(i, 13).Value = rng.Offset(0, 6).Value
.Cells(i, 14).Value = rng.Offset(0, 5).Value
.Cells(i, 15).Value = rng.Offset(0, 4).Value
.Cells(i, 16).Value = rng.Offset(0, 8).Value
End With
End If
Next i
End Sub
I'll post the whole code. I also made an adjustment to your first line of declarations - as you had it, only totalrows was being declared as Long. You have to spell each one out I'm afraid.
Sub lookup()
Dim lLastrow As Long, totalrows As Long
Dim rng As Range
Dim i As Long
With Sheets("S")
lLastrow = .Cells(.Rows.Count, 1).End(xlUp).Row
.Range("P5:P" & lLastrow).Copy Destination:=Sheets("Data").Range("E5")
.Range("G5:G" & lLastrow).Copy Destination:=Sheets("Data").Range("H5")
End With
totalrows = Sheets("P").Cells(Sheets("P").Rows.Count, "A").End(xlUp).Row
For i = 5 To lLastrow
'Search for the value on P_APQP
With Sheets("P")
'amended below
Set rng = .Columns(1).Find(Trim(Sheets("Data").Cells(i, 5).Value) & "*", lookat:=xlWhole)
End With
'If it is found put its value on the destination sheet
If Not rng Is Nothing Then
With Sheets("Data")
.Cells(i, 6).Value = rng.Value
.Cells(i, 1).Resize(, 3).Value = rng.Offset(0, 1).Value
.Cells(i, 2).Value = rng.Offset(0, 2).Value
.Cells(i, 3).Value = rng.Offset(0, 3).Value
.Cells(i, 4).Value = rng.Offset(0, 9).Value
.Cells(i, 9).Value = rng.Offset(0, 10).Value
.Cells(i, 13).Value = rng.Offset(0, 6).Value
.Cells(i, 14).Value = rng.Offset(0, 5).Value
.Cells(i, 15).Value = rng.Offset(0, 4).Value
.Cells(i, 16).Value = rng.Offset(0, 8).Value
End With
End If
Next i
End Sub
Can someone please help me in my time of need. I have created a userform which is entering in a hyperlink dependent on dropdowns from a listbox.
Despite the hyperlink actually going in when the submit button is pressed, I am still receiving the error message of
Run-Time error 1004. Application-defined or object defined error.
When I debug ws.cells(iRow, 4) is the line highlighted
Private Sub Comm1_Click()
Dim iRow As Long
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim rng As Range
Set ws = Worksheets("QttOutlay")
Set ws2 = Worksheets("LookupVals")
iRow = ws.Cells.Find(what:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
Set rng = ws.Cells(iRow)
ws.Cells(iRow, 2).Value = RmRef.Value
ws.Cells(iRow, 3).Value = RetMod.Value
ws.Cells(iRow, 4).Value = rng.Parent.Hyperlinks.Add(Anchor:=rng, Address:=WorksheetFunction.VLookup(RetMod.Value, ws2.Range("A:B"), 2, False), TextToDisplay:="Info")
ws.Cells(iRow, 5).Value = OrdCod.Value
ws.Cells(iRow, 6).Value = hmm.Value
ws.Cells(iRow, 7).Value = lmm.Value
ws.Cells(iRow, 8).Value = rdtype.Value
ws.Cells(iRow, 9).Value = dtt.Value
ws.Cells(iRow, 10).Value = Wtt.Value
ws.Cells(iRow, 11).Value = Qt.Value
ws.Cells(iRow, 12).Value = LPc.Value
ws.Cells(iRow, 13).Value = Dt.Value
ws.Cells(iRow, 14).Value = (LPc.Value * Dt.Value) * Qt.Value
End Sub
The Hyperlinks.Add Method returns a hyperlink object which you are trying to assign to a cells value: ws.Cells(iRow, 4).Value = rng.Parent.Hyperlinks.Add(…). That won't work.
I guess that ws.Cells(iRow, 4) is meant to be the anchor of the hyperlink like: Anchor:=ws.Cells(iRow, 4)
So instead of
ws.Cells(iRow, 4).Value = rng.Parent.Hyperlinks.Add(Anchor:=rng, Address:=WorksheetFunction.VLookup(RetMod.Value, ws2.Range("A:B"), 2, False), TextToDisplay:="Info")
you should replace the whole line with something like this
ws.Hyperlinks.Add Anchor:=ws.Cells(iRow, 4), Address:=WorksheetFunction.VLookup(RetMod.Value, ws2.Range("A:B"), 2, False), TextToDisplay:="Info"
I wanted to reach out on a concern i am getting with with my loop. i need to copy all trainee data in the class list sheet from rows 13 on and put it into a roster registry sheet same workbook. however the code i wrote initially is giving me and error when i use .Range(i, 1) so i changed it to .Cells. Main concern is that the code writes the data into the roster registry sheet but only the last trainee data.
Option Explicit
Sub ExportcReg()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim wbk1 As Workbook
Dim s1, cReg As Worksheet
Dim x, i, FinalRow As Long
Dim thisvalue As String
Set wbk1 = Workbooks.Open(ThisWorkbook.Worksheets("Info").Range("A1").Value)
Set s1 = wbk1.Sheets("ClassRegistry")
Set cReg = ThisWorkbook.Worksheets("Class Registry")
With cReg
' Find the last row of data in Column "A"
FinalRow = .Cells(.Rows.Count, "A").End(xlUp).Row
' Loop through each row
For x = 2 To FinalRow
' Decide if to copy based on column A
thisvalue = .Cells(x, 1).Value
If thisvalue <> "" Then
i = s1.Cells(s1.Rows.Count, 1).End(xlUp).Row + 1
s1.Cells(i, 1).Value = thisvalue
s1.Cells(i, 2).Value = .Cells(x, 2).Value
s1.Cells(i, 3).Value = .Cells(x, 3).Value
s1.Cells(i, 4).Value = .Cells(x, 4).Value
s1.Cells(i, 5).Value = .Cells(x, 5).Value
s1.Cells(i, 6).Value = .Cells(x, 5).Value
s1.Cells(i, 7).Value = .Cells(x, 7).Value
s1.Cells(i, 8).Value = .Cells(x, 8).Value
s1.Cells(i, 9).Value = .Cells(x, 9).Value
s1.Cells(i, 10).Value = .Cells(x, 10).Value
s1.Cells(i, 11).Value = .Cells(x, 11).Value
s1.Cells(i, 12).Value = .Cells(x, 12).Value
s1.Cells(i, 13).Value = .Cells(x, 13).Value
s1.Cells(i, 14).Value = .Cells(x, 14).Value
s1.Cells(i, 15).Value = .Cells(x, 15).Value
s1.Cells(i, 16).Value = .Cells(x, 16).Value
s1.Cells(i, 17).Value = .Cells(x, 17).Value
s1.Cells(i, 18).Value = .Cells(x, 18).Value
End If
Next x
End With
wbk1.Close savechanges:=True
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
You have too much logical and technical errors in your code which I cannot explain line by line. Besides you can achieve your goal with less coding. Maybe what you need is a working code to understand how things work. Take a look at this:
Sub CListtoRReg()
'From Class List to Roster Registry
Dim ws1 As Worksheet: Set ws1 = Worksheets("Class List")
Dim ws2 As Worksheet: Set ws2 = Worksheets("Roster Registry")
Dim i, j As Long
For i = 13 To ws1.Cells(1, 1).End(xlDown).Row
ws2.Cells(1, 1).End(xlDown).Offset(1) = ws1.Range("C2").Value
For j = 2 To 11
ws2.Cells(1, 1).End(xlDown).Offset(0, j - 1) = ws1.Cells(i, j - 1).Value
Next j
Next i
End Sub