Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Copy Rows based on column value

Hi,

This may be a pretty complicated coding situation but I was hoping
that somebody might be able to help out.

I am trying to copy rows based on a certain value found in Column B

For example, If the value 1 exists in B I would like to copy all of
the rows that contain that value in column B and paste it into a new
workbook.

If the value in column B equals 2 then I would like to copy all of
those values into a different workbook

My problem arises because sometimes column B may contain values up to
15 in one instance while in another it may contain values up to 18 so
I cannot hard code the macro.

So could anybody help me with some code to scan column B and copy rows
based on the values that exist.

Here is an example of the code I have found to copy 1 value to a
different workbook

this macro assumes that your first row of data is a header row.
'will copy a row from one worksheet, to another blank workbook
'IF there is a 0 in column N
'Variables used by the macro
Application.ScreenUpdating = False
Dim FilterCriteria
Dim CurrentFileName As String
Dim NewFileName As String

'Get the current file's name
CurrentFileName = ActiveWorkbook.Name
'Select Range
'(note you can change this to meet your requirements)
Range("A1:AS3000").Select
'Apply Autofilter
Selection.AutoFilter
FilterCriteria = 1
'NOTE - this filter is on column N (field:=14), to change
'to a different column you need to change the field number
Selection.AutoFilter field:=2, Criteria1:=FilterCriteria
'Select the visible cells (the filtered data)
Selection.SpecialCells(xlCellTypeVisible).Select
'Copy the cells
Selection.Copy
'Open a new file
Workbooks.Add Template:="Workbook"
'Get this file's name
NewFileName = ActiveWorkbook.Name
'Make sure you are in cell A1
Range("A1").Select
'Paste the copied cells
ActiveSheet.Paste
'Clear the clipboard contents
Application.CutCopyMode = False
'Go back to the original file
Workbooks(CurrentFileName).Activate
'Clear the autofilter
Selection.AutoFilter field:=1
'Take the Autofilter off
Selection.AutoFilter
'Go to A1
Range("A1").Select
Application.ScreenUpdating = True
End Sub

Thanks so much for the help.

Sincerely,
Ben
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Copy Rows based on column value

Do you want to selectively copy values (you have a list to copy), or do you
just want to split all the different values in Column B to a new workbook for
each value?

Can the values in column B be sorted?

Barb Reinhardt




"Moneyball Wilson" wrote:

Hi,

This may be a pretty complicated coding situation but I was hoping
that somebody might be able to help out.

I am trying to copy rows based on a certain value found in Column B

For example, If the value 1 exists in B I would like to copy all of
the rows that contain that value in column B and paste it into a new
workbook.

If the value in column B equals 2 then I would like to copy all of
those values into a different workbook

My problem arises because sometimes column B may contain values up to
15 in one instance while in another it may contain values up to 18 so
I cannot hard code the macro.

So could anybody help me with some code to scan column B and copy rows
based on the values that exist.

Here is an example of the code I have found to copy 1 value to a
different workbook

this macro assumes that your first row of data is a header row.
'will copy a row from one worksheet, to another blank workbook
'IF there is a 0 in column N
'Variables used by the macro
Application.ScreenUpdating = False
Dim FilterCriteria
Dim CurrentFileName As String
Dim NewFileName As String

'Get the current file's name
CurrentFileName = ActiveWorkbook.Name
'Select Range
'(note you can change this to meet your requirements)
Range("A1:AS3000").Select
'Apply Autofilter
Selection.AutoFilter
FilterCriteria = 1
'NOTE - this filter is on column N (field:=14), to change
'to a different column you need to change the field number
Selection.AutoFilter field:=2, Criteria1:=FilterCriteria
'Select the visible cells (the filtered data)
Selection.SpecialCells(xlCellTypeVisible).Select
'Copy the cells
Selection.Copy
'Open a new file
Workbooks.Add Template:="Workbook"
'Get this file's name
NewFileName = ActiveWorkbook.Name
'Make sure you are in cell A1
Range("A1").Select
'Paste the copied cells
ActiveSheet.Paste
'Clear the clipboard contents
Application.CutCopyMode = False
'Go back to the original file
Workbooks(CurrentFileName).Activate
'Clear the autofilter
Selection.AutoFilter field:=1
'Take the Autofilter off
Selection.AutoFilter
'Go to A1
Range("A1").Select
Application.ScreenUpdating = True
End Sub

Thanks so much for the help.

Sincerely,
Ben

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Copy Rows based on column value

Hi Moneyball

See
http://www.rondebruin.nl/copy5.htm#workbook

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Moneyball Wilson" wrote in message
...
Hi,

This may be a pretty complicated coding situation but I was hoping
that somebody might be able to help out.

I am trying to copy rows based on a certain value found in Column B

For example, If the value 1 exists in B I would like to copy all of
the rows that contain that value in column B and paste it into a new
workbook.

If the value in column B equals 2 then I would like to copy all of
those values into a different workbook

My problem arises because sometimes column B may contain values up to
15 in one instance while in another it may contain values up to 18 so
I cannot hard code the macro.

So could anybody help me with some code to scan column B and copy rows
based on the values that exist.

Here is an example of the code I have found to copy 1 value to a
different workbook

this macro assumes that your first row of data is a header row.
'will copy a row from one worksheet, to another blank workbook
'IF there is a 0 in column N
'Variables used by the macro
Application.ScreenUpdating = False
Dim FilterCriteria
Dim CurrentFileName As String
Dim NewFileName As String

'Get the current file's name
CurrentFileName = ActiveWorkbook.Name
'Select Range
'(note you can change this to meet your requirements)
Range("A1:AS3000").Select
'Apply Autofilter
Selection.AutoFilter
FilterCriteria = 1
'NOTE - this filter is on column N (field:=14), to change
'to a different column you need to change the field number
Selection.AutoFilter field:=2, Criteria1:=FilterCriteria
'Select the visible cells (the filtered data)
Selection.SpecialCells(xlCellTypeVisible).Select
'Copy the cells
Selection.Copy
'Open a new file
Workbooks.Add Template:="Workbook"
'Get this file's name
NewFileName = ActiveWorkbook.Name
'Make sure you are in cell A1
Range("A1").Select
'Paste the copied cells
ActiveSheet.Paste
'Clear the clipboard contents
Application.CutCopyMode = False
'Go back to the original file
Workbooks(CurrentFileName).Activate
'Clear the autofilter
Selection.AutoFilter field:=1
'Take the Autofilter off
Selection.AutoFilter
'Go to A1
Range("A1").Select
Application.ScreenUpdating = True
End Sub

Thanks so much for the help.

Sincerely,
Ben


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
Copy rows to multiple sheets based off column value Wester Excel Programming 0 October 19th 06 04:12 AM
Copy rows of one sheet into mutiple sheets based on column value Wesley Breshears Excel Discussion (Misc queries) 0 October 18th 06 03:19 PM
Auto Fill Column with Date based on rows in other column JOUIOUI Excel Programming 2 June 6th 06 06:28 PM
MACRO - copy rows based on value in column to another sheet Michael A Excel Discussion (Misc queries) 1 March 5th 05 02:15 AM
MACRO - copy rows based on value in column to another sheet Mike Excel Programming 2 March 5th 05 12:21 AM


All times are GMT +1. The time now is 12:41 PM.

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

About Us

"It's about Microsoft Excel"