Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Search specific columnheading and copy/insert this column to locationcolumn A

Goodmorning,

In a macro I copy/insert a certain column to A.
This is mostly the same column location, but.... it's not for sure. It should be nice if the macro check this first. It's a bit a nice to have macro :)

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.


regards, Johan



  #2   Report Post  
Posted to microsoft.public.excel.programming
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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Search specific columnheading and copy/insert this column tolocation column A

Great !!! Thx. !!
regards, Johan

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default Search specific columnheading and copy/insert this column to location column A

A more brief version...

Sub MoveColumn2()
Dim c As Range

Set c = ActiveSheet.Range("1:1").Find("ABCD", lookat:=xlPart)
If Not c Is Nothing Then
If c.Column = 1 Then
MsgBox "Heading 'ABCD' is already in column A", vbInformation
Else
Columns(c.Column).Cut: Columns(1).Insert Shift:=xlToRight
MsgBox "Heading 'ABCD' was found and moved to column A", vbInformation
End If
Else
MsgBox "Heading 'ABCD' does not exist", vbExclamation
End If
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Column after specific text title the new column and add for David Excel Discussion (Misc queries) 5 October 2nd 09 04:03 PM
Search specific column for a variable date J Smith 555[_2_] Excel Programming 6 November 4th 08 08:25 PM
VBA to Search, Insert Column and Sum Richard Excel Programming 4 May 11th 07 06:36 AM
Search for text with specific parameter and copy boronmr Excel Programming 9 September 9th 06 09:04 PM
search column for specific cell using vba dave91 Excel Programming 1 July 30th 05 05:59 PM


All times are GMT +1. The time now is 01:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"