Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
MAWII
 
Posts: n/a
Default Copying cells with a macro

I'm working on a spreadsheet that performs some calculations and I have a
button that creates and renames a new worksheet if pressed. I need/would
like for the same button to also copy some information from this original
worksheet into the new sheet if certain conditions exist. For instance, if
the button is pressed, a new sheet is opened, renamed and original data is
checked to see if the column B value=1. If it does, the next few columns
within that row are copied to the new sheet. There may/will also be multiple
entries with a 1 in column B and I need all of those entries copied to the
new worksheet.
Thanks!
  #2   Report Post  
Bernie Deitrick
 
Posts: n/a
Default

MAW,

Try something like the macro below. You can modify it to suit your specific
needs. Assumes your data table starts in cell A1.

HTH,
Bernie
MS Excel MVP

Sub Export1s_to_SeparateSheets()
'Export is based on the value in column B
Dim mySht As Worksheet
Dim myCurSht As Worksheet
Dim KeyCol As Integer

KeyCol = 2
Set myCurSht = ActiveSheet
Set mySht = Worksheets.Add(befo=Worksheets(1))
mySht.Name = "New Sheet"
With myCurSht.Range("B1").CurrentRegion
.AutoFilter Field:=KeyCol, Criteria1:=1
.SpecialCells(xlCellTypeVisible).Copy _
mySht.Range("A1")
mySht.Cells.EntireColumn.AutoFit
.AutoFilter
End With

End Sub





"MAWII" wrote in message
...
I'm working on a spreadsheet that performs some calculations and I have a
button that creates and renames a new worksheet if pressed. I need/would
like for the same button to also copy some information from this original
worksheet into the new sheet if certain conditions exist. For instance,

if
the button is pressed, a new sheet is opened, renamed and original data is
checked to see if the column B value=1. If it does, the next few columns
within that row are copied to the new sheet. There may/will also be

multiple
entries with a 1 in column B and I need all of those entries copied to the
new worksheet.
Thanks!



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
How do I pause a macro to select specific cells lee Excel Worksheet Functions 1 April 2nd 05 02:11 PM
Macro to delete data in 'green' cells only Steve Excel Worksheet Functions 7 March 19th 05 01:40 PM
copying cells from other worksheets yesbob Excel Discussion (Misc queries) 1 February 7th 05 05:18 PM
Copying a workbook with custom toolbar assigned to a macro Matt W Excel Discussion (Misc queries) 1 February 4th 05 10:46 PM
copying text into a macro pagelocator Excel Worksheet Functions 1 November 24th 04 08:52 AM


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