Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Copy columns if

Hi, I need to copy columns B, C & H only if Column L = M1 from
sheets("Totals") to sheets("July")

Can some body help me on this pls..
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Copy columns if

IF {condition} then

with Worksheets("Total")
.Columns("B").Copy Worksheets("July").Columns("B")
.Columns("C").Copy Worksheets("July").Columns("C")
.Columns("H").Copy Worksheets("July").Columns("H")
End With

end if

{condition}
I wasn't sure what you meant by
Column L = M1

??

"Kash" wrote in message
...
Hi, I need to copy columns B, C & H only if Column L = M1 from
sheets("Totals") to sheets("July")

Can some body help me on this pls..


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Copy columns if


Sorry if I wasn't clear..

M1 is date

So, if L10:L30=M1 then I need corresponding rows form columns B, C & H only
to be copied to sheets("Totals") to sheets("July")
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Copy columns if


You can copy adjacent columns with one Copy method call (it is only
noncontiguous ranges that can't be handled by a single Copy method call)...

.Columns("B:C").Copy Worksheets("July").Range("B1")
.Columns("H").Copy Worksheets("July").Range("H1")

--
Rick (MVP - Excel)


"Patrick Molloy" wrote in message
...
IF {condition} then

with Worksheets("Total")
.Columns("B").Copy Worksheets("July").Columns("B")
.Columns("C").Copy Worksheets("July").Columns("C")
.Columns("H").Copy Worksheets("July").Columns("H")
End With

end if

{condition}
I wasn't sure what you meant by
Column L = M1

??

"Kash" wrote in message
...
Hi, I need to copy columns B, C & H only if Column L = M1 from
sheets("Totals") to sheets("July")

Can some body help me on this pls..



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Copy columns if

I tried with below code, but getting 'Type mismatch' error in 1st line


If Worksheets("Totals").Columns("L") = Worksheets("Totals").Range("M2") Then

With Worksheets("Totals")
..Columns("B").Copy Worksheets("Sheet1").Columns("B")
..Columns("C").Copy Worksheets("Sheet1").Columns("C")
..Columns("H").Copy Worksheets("Sheet1").Columns("D")

End With
End If


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Copy columns if


my code was for copying the entire column, given that we were not clear
about your filter.
Now i understand that for each row, if the value in L matches the value in
cell M1, then just that row must be copied.

Using an Autofilter should work

Sub FilterMe()

Range("C1:L1").AutoFilter ' turn on the filter
Selection.AutoFilter Field:=10, Criteria1:=Range("M1")
Range("C:D").Cells.SpecialCells(xlCellTypeVisible) .Copy
Sheets("Sheet2").Range("C1")
Range("H:H").Cells.SpecialCells(xlCellTypeVisible) .Copy
Sheets("Sheet2").Range("H1")
Range("C1:L1").AutoFilter ' turn off the filter
End Sub

"Kash" wrote in message
...
I tried with below code, but getting 'Type mismatch' error in 1st line


If Worksheets("Totals").Columns("L") = Worksheets("Totals").Range("M2")
Then

With Worksheets("Totals")
.Columns("B").Copy Worksheets("Sheet1").Columns("B")
.Columns("C").Copy Worksheets("Sheet1").Columns("C")
.Columns("H").Copy Worksheets("Sheet1").Columns("D")

End With
End If


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
Change a Macro - Copy in Columns instead of copy in Rows ytayta555 Excel Programming 7 May 9th 09 06:32 PM
copy a columns kevcar40 Excel Discussion (Misc queries) 2 September 18th 08 10:42 AM
How do I copy columns between worksheets if the columns don't matc Miriam Excel Worksheet Functions 10 June 12th 06 04:29 PM
Copy columns values into separate columns Mike_can Excel Discussion (Misc queries) 7 May 27th 06 12:32 AM
Copy a row from one sheet to another and not all columns copy Peaches[_2_] Excel Programming 2 September 7th 05 12:09 PM


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