SilverSlug
New Member
- Joined
- Oct 28, 2015
- Messages
- 6
I'm working on a code in VBA to copy rows from sheet "ALL FILES" and paste them into "VIEW STUDENT" based on "JOHN SMITH". Right now it copies the entire row, but I only want to select columns D, E, H-AB (4, 5, 8-28) in the same row. Any ideas?
I also need to edit the code so it searches for the value of a ListBox. Any ideas?
Code:
Sub RunMain()
Dim r As Long, endRow As Long, pasteRowIndex As Long
Sheets("ALL FILES").Select
endRow = 50
pasteRowIndex = 1
For r = 1 To endRow
If Cells(r, Columns("B").Column).Value = "JOHN SMITH" Then 'Found
'I BELIEVE THAT THIS CODE NEEDS TO BE CHANGED...
'Copy the current row
Rows(r).Select
Selection.Copy
Sheets("view students").Select
Rows(pasteRowIndex).Select
ActiveSheet.Paste
'Next time you find a match, it will be pasted in a new row
pasteRowIndex = pasteRowIndex + 1
'Switch back to your table & continue to search for your criteria
Sheets("ALL FILES").Select
End If
Next r
'REVET TO VIEW NORMAL SHEET AGAIN
Worksheets("view students").Activate
'CLEAR CLIPBOARD
Application.CutCopyMode = False
'ADDS BLANK ROWS TO TOP OF CHART
Rows("1:1").Select
Range("B1").Activate
End Sub
I also need to edit the code so it searches for the value of a ListBox. Any ideas?