Carlen
New Member
I am new to VBA and trying to convert the following code to work on a loop from a range of variable length. The range will start A column of the sheet starting on A6 but will end depending on how many variables (rows) are present.
This is the main code:
In this case the program is selecting the cells between the teacher names listed in spots A6 and A7 of the teachers sheets, pasting into Calcie, copying the output and pasting it Output under A5. Essentially I am trying to make a loop that would go to A7 & A8 of teachers than paste in A6 in output and so on until the end of the teacher list.
Any help here would be greatly appreciated!
This is the main code:
Code:
Sub Run()
'
' Run Macro
' Teacher 1
Dim nRow As Long
Dim nStart As Long, nEnd As Long
' Figure out where the range should start.
For nRow = 1 To 100000
If Range("A" & nRow).Value = ThisWorkbook.Sheets("Teachers").Range("A6") Then
nStart = nRow
Exit For
End If
Next nRow
' Figure out where the range should end.
For nRow = nStart To 100000
If Range("A" & nRow).Value = ThisWorkbook.Sheets("Teachers").Range("A7") Then
nEnd = nRow
Exit For
End If
Next nRow
nEnd = nEnd - 1
' Copy and paste selected range.
Range("A" & nStart & ":D" & nEnd).Select
Selection.Copy
ThisWorkbook.Sheets("Calcie").Activate
Range("A6").Select
ActiveSheet.Paste
' Copy output and paste in Output
Range("B4", "W4").Select
Selection.Copy
ThisWorkbook.Sheets("Output").Activate
Range("A5").PasteSpecial Paste:=xlPasteValues
End Sub
In this case the program is selecting the cells between the teacher names listed in spots A6 and A7 of the teachers sheets, pasting into Calcie, copying the output and pasting it Output under A5. Essentially I am trying to make a loop that would go to A7 & A8 of teachers than paste in A6 in output and so on until the end of the teacher list.
Any help here would be greatly appreciated!