PC Review


Reply
Thread Tools Rate Thread

Copy columns if

 
 
Kash
Guest
Posts: n/a
 
      27th Jun 2009
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..
 
Reply With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      27th Jun 2009
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" <(E-Mail Removed)> wrote in message
news:866C58D6-4E88-439B-8CB2-(E-Mail Removed)...
> 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..


 
Reply With Quote
 
Kash
Guest
Posts: n/a
 
      27th Jun 2009

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")
 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      27th Jun 2009

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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:866C58D6-4E88-439B-8CB2-(E-Mail Removed)...
>> 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..

>


 
Reply With Quote
 
Kash
Guest
Posts: n/a
 
      27th Jun 2009
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 With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      28th Jun 2009

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").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" <(E-Mail Removed)> wrote in message
news:9F31C97F-6A0F-44D5-9FCC-(E-Mail Removed)...
> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change a Macro - Copy in Columns instead of copy in Rows ytayta555 Microsoft Excel Programming 7 9th May 2009 06:32 PM
How do I copy columns between worksheets if the columns don't matc =?Utf-8?B?TWlyaWFt?= Microsoft Excel Worksheet Functions 10 12th Jun 2006 04:29 PM
Copy columns values into separate columns =?Utf-8?B?TWlrZV9jYW4=?= Microsoft Excel Misc 7 27th May 2006 12:32 AM
password protected document with hidden columns, columns appear when copy-pasted onarol@gmail.com Microsoft Excel Discussion 2 4th Apr 2006 01:21 PM
Re: Copy a row from one sheet to another and not all columns copy Peaches Microsoft Excel Programming 0 7th Sep 2005 12:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:59 AM.