Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Copy sheets only if condition is satisfied (mat)

Hi guys,

i want a macro to do the following:

I have a masterfile with several sheets. If I run the macro i want it
to copy sheet1 and/orsheet2 and /or sheet 3 to a new workbook
depending on a condition.

Sheet 1 has to be copied always
Sheet 2 has to be copied only if the cell A2 from sheet 1 is the same
as the cell A2 from sheet 2
Sheet 3 has to be copied only if the cell A2 from sheet 1 is the same
as the cell A2 from sheet3

the sheets have to be copied as values and with the format off the
sheets from the masterfile.

Thanks guys

mat

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Copy sheets only if condition is satisfied (mat)

Hi matthias

Try this basic code example

Sub TestCopy()
If Sheets("Sheet1").Range("A2").Value = Sheets("Sheet2").Range("A2").Value Then
If Sheets("Sheet1").Range("A2").Value = Sheets("Sheet3").Range("A2").Value Then
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Copy
Else
Sheets(Array("Sheet1", "Sheet2")).Copy
End If
Else
If Sheets("Sheet1").Range("A2").Value = Sheets("Sheet3").Range("A2").Value Then
Sheets(Array("Sheet1", "Sheet3")).Copy
Else
Sheets("Sheet1").Copy
End If
End If

Worksheets.Select
Cells.Copy
Cells.PasteSpecial xlPasteValues
Cells(1).Select
Worksheets(1).Select
Application.CutCopyMode = False

End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"matthias" wrote in message oups.com...
Hi guys,

i want a macro to do the following:

I have a masterfile with several sheets. If I run the macro i want it
to copy sheet1 and/orsheet2 and /or sheet 3 to a new workbook
depending on a condition.

Sheet 1 has to be copied always
Sheet 2 has to be copied only if the cell A2 from sheet 1 is the same
as the cell A2 from sheet 2
Sheet 3 has to be copied only if the cell A2 from sheet 1 is the same
as the cell A2 from sheet3

the sheets have to be copied as values and with the format off the
sheets from the masterfile.

Thanks guys

mat



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Copy sheets only if condition is satisfied (mat)

thanks ron!! now, can I ask you another thing?
now the macro runs perfectly, but can i also make sure that the copies
of the sheets are in "landscape form" as the originals?

thanks

ps ik spreek ook nederlands

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Copy sheets only if condition is satisfied (mat)

I test it with one of the sheets set to landscape and in the new workbook it is also landscape ?
Do you get a different result

--
Regards Ron de Bruin
http://www.rondebruin.nl


"matthias" wrote in message ups.com...
thanks ron!! now, can I ask you another thing?
now the macro runs perfectly, but can i also make sure that the copies
of the sheets are in "landscape form" as the originals?

thanks

ps ik spreek ook nederlands



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Copy sheets only if condition is satisfied (mat)

no it's indeed OK

thanks a lot mate



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Copy sheets only if condition is satisfied (mat)

hi maybe one extra question

if i run the macro via a button, he copies the button to the new
workbook since it is part of sheet1. how can i avoid this. if know it
is something with shapes...(it is a button from forms), it has to be
put in the code above?

mat

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Copy sheets only if condition is satisfied (mat)

you can delete the shapes on the activesheet with this


Sub Forms1()'Delete All Forms buttons ActiveSheet.Buttons.DeleteEnd Sub



--
Regards Ron de Bruin
http://www.rondebruin.nl


"matthias" wrote in message oups.com...
hi maybe one extra question

if i run the macro via a button, he copies the button to the new
workbook since it is part of sheet1. how can i avoid this. if know it
is something with shapes...(it is a button from forms), it has to be
put in the code above?

mat



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Copy sheets only if condition is satisfied (mat)

This is better

Sub Forms1()
'Delete All Forms buttons
ActiveSheet.Buttons.Delete
End Sub



--
Regards Ron de Bruin
http://www.rondebruin.nl


"Ron de Bruin" wrote in message ...
you can delete the shapes on the activesheet with this


Sub Forms1()'Delete All Forms buttons ActiveSheet.Buttons.DeleteEnd Sub



--
Regards Ron de Bruin
http://www.rondebruin.nl


"matthias" wrote in message oups.com...
hi maybe one extra question

if i run the macro via a button, he copies the button to the new
workbook since it is part of sheet1. how can i avoid this. if know it
is something with shapes...(it is a button from forms), it has to be
put in the code above?

mat





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
Formula to get data when condition is satisfied Kashyap Excel Worksheet Functions 1 November 10th 08 01:17 PM
countif and sum if if two condition are satisfied zafar62 Excel Worksheet Functions 3 July 15th 08 06:22 AM
Looping till condition is satisfied? Jo[_2_] Excel Worksheet Functions 3 October 4th 07 09:43 PM
How to change the value of a cell when a condition is satisfied, but not otherwise? benzi_k_ahamed Excel Discussion (Misc queries) 0 January 11th 06 11:31 AM
Deletion of rows where a value is satisfied for all the sheets Rashid Khan Excel Programming 2 March 26th 05 05:03 AM


All times are GMT +1. The time now is 04:57 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"