View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Search specific columnheading and copy/insert this column to location column A

Hi Johan,

Am Sun, 29 Sep 2019 05:39:49 -0700 (PDT) schrieb JS SL:

Actions;
1) In the active sheet search for the column with in the headingrow (row1) a specific text, like for example 'ABCD'.

2a) If not found this columnheading give a popup message "Columnheading 'ABCD' not exist". Then the macro stops.
2b) If found columnheading 'ABCD' but this is column A then give a popup message "Columnheading 'ABCD' is already placed on A". Then the macro stops.

3) If found, and not placed on location Column A, then copy this whole column and copy/insert this column at the place of column A. Then this become column A and all the other columns will move to the right.


try:

Sub MoveColumn()
Dim c As Range

With ActiveSheet
Set c = .Range("1:1").Find("ABCD", lookat:=xlPart)
If c Is Nothing Then
MsgBox "Columnheading 'ABCD' not exist"
Exit Sub
End If

If Not c Is Nothing And c.Column < 1 Then
Columns(c.Column).Cut
Columns(1).Insert Shift:=xlToRight
ElseIf Not c Is Nothing And c.Column = 1 Then
MsgBox "Columnheading 'ABCD' is already placed on A"
Exit Sub
End If
End With
End Sub


Regards
Claus B.
--
Windows10
Office 2016