Hi All
Please can someone help me understand the following code.
I needed to collate all sheets onto one sheet to pivot data from it. I found this code online and it works perfectly however I don't understand why it does and hope someone here can explain it in very basic and simple terms to someone who knows very little about coding:
In the below code:
Line 1 - where does "J" come from, what is that? Why is it J?
Line 2 - what does "On error Resume Next" mean?
I do follow lines 3 - 5
Line 6 - I have no sheet called "Sheets(2)" so what is this doing?
Line 8 - same question there is nothing called "Sheets(1)" so how does this reference work?
Line 9 - hopefully will be answered above but what is "J". Why equal "2"?
Sub Combine()
1 Dim J As Integer
2 On Error Resume Next
3 Sheets(1).Select
4 Worksheets.Add
5 Sheets(1).Name = "Combined"
6 Sheets(2).Activate
7 Range("A1").EntireRow.Select
8 Selection.Copy Destination:=Sheets(1).Range("A1")
9 For J = 2 To Sheets.Count
10 Sheets(J).Activate
11 Range("A1").Select
12 Selection.CurrentRegion.Select
13 Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select
14 Selection.Copy Destination:=Sheets(1).Range("A65536").End(xlUp)(2)
Next
End Sub
The code does work however I am needing to do a lot more in vba and am still clearly battling with the basics.
I am going through this website and this https://powerspreadsheets.com/vba-sub-procedures/ which seems pretty good however as often happens, I need to actually be creating the sheets and not learning about them so any assistance in speeding up the process would be highly appreciated.
Thank you
Bookmarks