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

Hi

Newbie here hoping some help. I have this code to copy a whole range to
another worsheet:
Dim rng1 As Range
Dim rng2 As Range
Set rng1 = Sheets("Sales-Inventory").Range("UPC",
Range("MK_ID").End(xlDown))
Set rng2 = Sheets("Sales-Inventory").Range("Figure",
Range("Figure").End(xlDown))
rng1.Copy
Sheets("BAUCS").Range("C11").PasteSpecial Paste:=xlValues, _
Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
rng2.Copy
Sheets("BAUCS").Range("C37").PasteSpecial Paste:=xlValues, _
Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
Application.CutCopyMode = True

End Sub

The problem with this code is that copies the whole range and I need to
change this code to look into column A and copy the values based on the value
located in this column to the corresponding worsheet. In column A I have six
options like this: RE,AS, KJ, JC, XC, MN I need to copy cells B, C and P to
differents worsheets which are named the same as the six options I mentioned
before. Did I explain clearly? Let me know.

Can anybody help me with this, please.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copy range based on condition

Dim sh as Worksheet, cell as Range
Dim rng3 as Range, rng1 as Range
With Worksheets("Sales-Inventory")
set rng1 = .Range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
End With

for each cell in rng
Set sh = Nothing
on Error Resume Next
set sh = Worksheets(cell)
On Error goto 0
if not sh is nothing then
set rng3 = sh.Cells(rows.count,1).End(xlup)(2)
sh.Cells(rng3.row,2) = cell.offset(0,1)
sh.Cells(rng3.row,3) = cell.offset(0,2)
sh.Cells(rng3.row,15) = cell.offset(0,15)
end if
Next

--
Regards,
Tom Ogilvy



"Sotomayor" wrote in message
...
Hi

Newbie here hoping some help. I have this code to copy a whole range to
another worsheet:
Dim rng1 As Range
Dim rng2 As Range
Set rng1 = Sheets("Sales-Inventory").Range("UPC",
Range("MK_ID").End(xlDown))
Set rng2 = Sheets("Sales-Inventory").Range("Figure",
Range("Figure").End(xlDown))
rng1.Copy
Sheets("BAUCS").Range("C11").PasteSpecial Paste:=xlValues, _
Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
rng2.Copy
Sheets("BAUCS").Range("C37").PasteSpecial Paste:=xlValues, _
Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
Application.CutCopyMode = True

End Sub

The problem with this code is that copies the whole range and I need to
change this code to look into column A and copy the values based on the
value
located in this column to the corresponding worsheet. In column A I have
six
options like this: RE,AS, KJ, JC, XC, MN I need to copy cells B, C and P
to
differents worsheets which are named the same as the six options I
mentioned
before. Did I explain clearly? Let me know.

Can anybody help me with this, please.

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
Copy and Paste based on Condition EJ Excel Discussion (Misc queries) 1 June 27th 07 11:17 PM
How do I copy a set of cells based on a logical condition getdv Excel Discussion (Misc queries) 1 October 24th 06 02:08 PM
Copy Row based on a condition [email protected] Excel Worksheet Functions 1 April 19th 06 06:05 PM
How to copy only some rows from range based on condition? [email protected][_2_] Excel Programming 2 January 30th 06 01:04 AM
Create/copy combo boxes in one range if condition is met in a different range LB[_4_] Excel Programming 4 September 30th 05 12:21 AM


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