copy rows from another workbook on two condition

malgorzata

New Member
Joined
Feb 2, 2018
Messages
4
Hey,

I've been looking for the answer to my current VBA issue, but couldn't find anything. Maybe someone in there knows how to solve the crisis.

I have two Excel files - one Workbook contains all the information on current/past/potencial clients[ALL CLIENTS'], and another one for just the potencial clients [PIPELINE].

I would like to copy the rows [from ALL CLIENTS] - if in "status" (coulmn F) cell appears "pipeline", and if cell (column K) contains "in progress" - and paste it to last rows of [PIPLELINE] workbook.

Do u know how this makro should look like? I'm quite new to VBA.

Thanks a lot in advance!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi & welcome to the board.
How about
Code:
Sub copyDataBetweenBooks()

   Dim OrigWs As Worksheet
   Dim destWs As Worksheet
   
   Set OrigWs = ThisWorkbook.Sheets("[COLOR=#0000ff]Data[/COLOR]")
   Set destWs = Workbooks("[COLOR=#ff0000]Pipeline.xlsx[/COLOR]").Sheets("[COLOR=#0000ff]Sheet1[/COLOR]")
   
   With OrigWs
      If .AutoFilterMode Then .AutoFilterMode = False
      With .Range("A1:K1")
         .AutoFilter 6, "pipeline"
         .AutoFilter 11, "in progress"
         .CurrentRegion.Offset(1).SpecialCells(xlVisible).Copy destWs.Range("A" & Rows.Count).End(xlUp).Offset(1)
      End With
      .AutoFilterMode = False
   End With
      
End Sub
This macro needs to go in a standard module in the All Clients workbook & both workbooks need to be open when you run it.
Change workbook name in red & sheet names in blue to suit.
 
Upvote 0
Hey, thanks for warm welcoming and the code, it works perfectly! :) I only have two (i hope quick) questions... Do u think it's posibble to choose specific cells of origin rowas which i needed to be implemented in new one, and is it possible to detect and avoid overlaps?
 
Upvote 0
By this
Do u think it's posibble to choose specific cells of origin row
do you mean copy only certain columns, rather than the entire row? If so which columns do you want to copy.


And by this
and is it possible to detect and avoid overlaps?
do you mean, make sure that the same data does not get duplicated in the Pipeline workbook? If so can we delete the current data in pipeline?
 
Upvote 0
By this do you mean copy only certain columns, rather than the entire row? If so which columns do you want to copy.

Lets say I have columns: ID - Name of client - city - service - status - date, and i would like to copy only information about ID, name of the client and service.

And by this do you mean, make sure that the same data does not get duplicated in the Pipeline workbook? If so can we delete the current data in pipeline?

Yes and yes :)
 
Upvote 0
Which columns do you want to copy? is it cols A,B & D?
 
Upvote 0
In that case try
Code:
Sub copyDataBetweenBooks()

   Dim OrigWs As Worksheet
   Dim destWs As Worksheet
   
   Set OrigWs = ThisWorkbook.Sheets("Data")
   Set destWs = Workbooks("Pipeline.xlsx").Sheets("Sheet1")
   
   With OrigWs
      If .AutoFilterMode Then .AutoFilterMode = False
      With .Range("A1:K1")
         .AutoFilter 6, "pipeline"
         .AutoFilter 11, "in progress"
         destWs.UsedRange.Clear
         .CurrentRegion.Range("A:B").SpecialCells(xlVisible).Copy destWs.Range("A1")
         .CurrentRegion.Range("D:D").SpecialCells(xlVisible).Copy destWs.Range("D1")
      End With
      .AutoFilterMode = False
   End With
      
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top