here is complete solution
Does not stop on blank cell (it stops if there are 3 (userdefined) blank
cell in a row)
If works on all sheets in a workbook
Custom list can be arranged in ColumnPlace function (just insert new
case line with whatever content of column and desired place of column
here is code:
Sub MoveandCountColumnsA()
Static CountBlanks
'Next two lines cycle thru worksheets
For Each a In Worksheets
a.Activate
10 For i = 1 To 254 'As 255 is maximum number of columns
If Len(Cells(1, i).Value) = 0 Then
CountBlanks = CountBlanks + 1
'If there is 3 columns in a row that was blank assume last column
If CountBlanks > 3 Then
'3 blanks in a row, assume we are over last column
Exit For
End If
Else
'Reset counter if there is only 1 or 2 blank cells
CountBlanks = 0
End If
col = ColumnPlace(Cells(1, i).Value, i)
If col <> i Then
Columns(col).Select
Selection.Copy
Columns(255).Select
ActiveSheet.Paste
Columns(i).Select
Selection.Copy
Columns(col).Select
ActiveSheet.Paste
Columns(255).Select
Selection.Copy
Columns(i).Select
ActiveSheet.Paste
GoTo 10
End If
Next
Next
End Sub
Public Function ColumnPlace(ColumnName, CurrColumn)
Select Case ColumnName
Case "NUM" 'Put here content of first cell of column
ColumnPlace = 1 'Put here desired place of column
Case "SYS"
ColumnPlace = 2
Case "DIA"
ColumnPlace = 3
Case "TAG"
ColumnPlace = 7
Case "VAR2"
ColumnPlace = 5
Case Else
ColumnPlace = CurrColumn
End Select
End Function
And avi, you are welcome, if there is anything you would like me to
change, just ask