ok for the development of this problem. I am sure there are variables defined that i don’t need and variable undefined…
This works as i want it too, bar one issue, because “A” counts across all the 8 worksheets i have set up, i have a lot of empty rows.
Suggestions as to the best way of removing these empty rows.
As i see it two ways, i can get the data copied to the right cell in the first place.
So i need to d something to
Worksheets(“data”).Rows(i).Copy Destination:=Worksheets(region).Rows(A)
Or i clean the data afterwards and remove the empty cells.
Ideas gratefully received!
Sub OrganiseData2()
Dim rowcountold As Integer
Dim i As Integer
Dim region As String
Dim companyname As String
Dim ws As Worksheet
Dim rng As range
Dim z As Integer
Set ws = Sheets(“accounts”)
Set rng = ws.range(“a2:c200”)
‘count the number of rows
rowcountold = Worksheets(“data”).UsedRange.Rows.Count
‘Loop through counting the rows and each that matches the criteria copy to another worksheet
A = 4
For z = 2 To 117
For i = 1 To rowcountold
companyname = Worksheets(“accounts”).Cells(z, 1).Value
If Cells(i, 1).Value = companyname Then
region = Application.WorksheetFunction.VLookup(companyname, rng, 3, 0)
Worksheets(“data”).Rows(i).Copy Destination:=Worksheets(region).Rows(A)
A = A + 1
Else: End If
Next i
Next z
End Sub