Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default Macro to copy adjacent columns for a specified condition

I am struggling with VBA macro to accomplish the following:

Step1:
If the word "frequency" in present in row 1 (A1, B1, C1... IV1) of any
worksheets of the existing workbook, then copy that column and a
column before it.

For example, if "frequency" is present in N1 of sheet4 AND AJ1 of
sheet13, then copy column M and N of sheet4 AND column AI and AJ of
sheet 13 etc...

Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
If Rows("1:1") = "frequency" then ' this is not correct :(
..............

Step2:
Open a new workbook and save as test.xls

Workbooks.Add
ActiveWorkbook.SaveAs Filename:= _
"C:\test.xls", FileFormat:=xlNormal _
, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False, _
CreateBackup:=False

Step3:
Paste the copied values of columns M and N of sheet4 (from step1) to
columns A and B of Sheet1 of the active workbook (test.xls) AND
Paste the copied values of columns AI and AJ of sheet13 (from step1)
to columns A and B of Sheet2 of the active workbook (test.xls)
etc.........

Saving the file can be done after step3 too..

Can someone be grateful to give me the macro accomplish these steps?
Thank you

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default Macro to copy adjacent columns for a specified condition

On Oct 24, 1:31 pm, wrote:
I am struggling with VBA macro to accomplish the following:

Step1:
If the word "frequency" in present in row 1 (A1, B1, C1... IV1) of any
worksheets of the existing workbook, then copy that column and a
column before it.

For example, if "frequency" is present in N1 of sheet4 AND AJ1 of
sheet13, then copy column M and N of sheet4 AND column AI and AJ of
sheet 13 etc...

Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
If Rows("1:1") = "frequency" then ' this is not correct :(
.............

Step2:
Open a new workbook and save as test.xls

Workbooks.Add
ActiveWorkbook.SaveAs Filename:= _
"C:\test.xls", FileFormat:=xlNormal _
, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False, _
CreateBackup:=False

Step3:
Paste the copied values of columns M and N of sheet4 (from step1) to
columns A and B of Sheet1 of the active workbook (test.xls) AND
Paste the copied values of columns AI and AJ of sheet13 (from step1)
to columns A and B of Sheet2 of the active workbook (test.xls)
etc.........

Saving the file can be done after step3 too..

Can someone be grateful to give me the macro accomplish these steps?
Thank you


Can someone help me with the VBA code please?

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
Add cells on two adjacent rows but non-adjacent columns Eve Excel Worksheet Functions 14 October 20th 09 02:32 AM
Copy Multiple non adjacent columns from one Worksheet to another Blubber Excel Discussion (Misc queries) 6 October 29th 08 03:52 AM
Merging adjacent repeated columns with a macro [email protected] Excel Discussion (Misc queries) 2 April 3rd 07 07:44 PM
Merging adjacent repeated columns with a macro [email protected] Excel Programming 2 April 3rd 07 07:44 PM
When data match, copy adjacent value to adjacent column slimbim Excel Worksheet Functions 2 November 8th 06 08:41 PM


All times are GMT +1. The time now is 09:23 AM.

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"