Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Copying data from one sheet to another

Start with a WB and one WS with a range of data.
I want to:
Add two new sheets
Check each record on the original sheet and
If Column B in that row = X then
Copy what's in Column A of that row to new Sheet2,
or
If Column B in that row = Y then
Copy what's in Column A of that row to new Sheet 3.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Copying data from one sheet to another

Try this:

Sub CopyXY()
Dim Sh1 As Worksheet
Dim shX As Worksheet
Dim shY As Worksheet

Set Sh1 = ActiveSheet
Set shX = Worksheets.Add(after:=Sh1)
Set shY = Worksheets.Add(after:=shX)

Sh1.Activate
FirstRow = 2 'Headings in row 1
LastRow = Range("B" & Rows.Count).End(xlUp).Row

For r = FirstRow To LastRow
If Cells(r, "B").Value = "X" Then
x = x + 1
Cells(r, "A").Copy shX.Cells(x, 1)
ElseIf Cells(r, "B").Value = "Y" Then
y = y + 1
Cells(r, "A").Copy shY.Cells(y, 1)
End If
Next
End Sub

Regards,
Per

On 27 Dec., 23:29, John Pierce wrote:
Start with a WB and one WS with a range of data.
I want to:
Add two new sheets
Check each record on the original sheet and
If Column B in that row = X then
Copy what's in Column A of that row to new Sheet2,
or
If Column B in that row = Y then
Copy what's in Column A of that row to new Sheet 3.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Copying data from one sheet to another

Per,
Thanks, that works for me!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Copying data from one sheet to another

Here's another one, similar but completely different.
Start with a WB with two existing sheets: Sh1, Sh2
Sh2 contains a lot of permanent records.
Sh1 contains temporary records for transfer to Sh2.
Sh1 has a header row and 7 columns (A-G) and
variable number of records.
I want to copy all records on Sh1 then paste on
Sh2 below existing records, BUT
Sh1 "A" goes in Sh2 "E"
Sh1 "B" goes in Sh2 "C"
Sh1 "C" goes in Sh2 "K"
etc.
I'm thinking copy Sh1 into a Dynamic Array and
then copy to Sh2 element by element?
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
Need help Taking alot data from one sheet (if not blank) and copying toa list on another sheet. Alex Zuniga Excel Worksheet Functions 1 November 25th 09 11:54 PM
copying only selected data from Sheet 1 to Sheet 2 Jaf Excel Worksheet Functions 2 September 1st 09 01:01 AM
Copying the repeated data of the previous sheet to the next sheet Sasikiran Excel Discussion (Misc queries) 1 September 25th 07 03:18 PM
Copying Data from one sheet to another sheet on a specific day Gav123 Excel Worksheet Functions 0 May 1st 07 10:17 AM
2 questions, copying data from sheet to sheet and assigning macro Boris Excel Worksheet Functions 0 December 16th 04 06:11 PM


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

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"