Hi all,
I have the following loop coded:
Sub Resort()
Application.ScreenUpdating = True
Dim i As Long
For i = Sheet4.ListObjects("SouthTable").DataBodyRange.Rows.Count + 1 To 2 Step -1
'LOOP TESTER
'Sheet4.ListObjects("SouthTable").Range(i, 1).Select
'Application.Wait (Now + TimeValue("00:00:01"))
If Sheet4.ListObjects("SouthTable").Range(i, Sheet4.ListObjects("SouthTable").ListColumns("Region").Range.Column).Value = "HQ" Then
Sheet4.ListObjects("SouthTable").ListRows(i - 1).Range.Cut Sheet4.ListObjects("HQTable").ListRows.Add.Range
Sheet4.ListObjects("SouthTable").ListRows(i - 1).Range.Delete
End If
Next i
End Sub
but I'm not convinced this is the best way to do this.
I don't like the i +1, i-1 parts.. Is there a better way to write this loop?
Context:
I have data sorted by regions (countries are in different regions) but some countries can belong to 2 regions, and the user needs to revise the original sort, and change the regions for some data, and this loop (button) would loop through (in this example) the "SouthTable" and if a user changed the region in the South Table for Headquarters (HQ) then cut that row (and delete the empty row) and (add a row into and) paste it into the HQ table.
Please see the example if its not understandable!
Looking for any ideas?
Thanks!!
Bookmarks