Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Macro to LookUp Data and Copy/Insert only Non-Duplicated Rows

This may be an easy one for a VBA guru.

I have to update a production schedule daily by sales order number. I need
to copy and insert non-duplicated rows from Worksheet 2 into Worksheet 1
according to a specific column. For example,

Worksheet 1
Col.A Sales # Col.B Description
1 Description #1
2 Description #2
3 Description #3

Worksheet 2
Col.A Sales # Col.B Description
1 Description #1
4 Description #4
5 Description #5


The macro should only insert the rows with sales # 4 & #5 from Wk Sht. 2 to
Wk Sht 1. Addtionally, the rows should be inserted below the last row with
text in it.

Any help on this would be greatly appreciated! Thank you so much in advance!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Macro to LookUp Data and Copy/Insert only Non-Duplicated Rows

try this code

Sub test()

With Sheets("Sheet1")
.Activate
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
Set Sh1Range = Range(.Cells(2, "A"), .Cells(LastRow, "A"))
End With

With Sheets("Sheet2")
.Activate
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
Set Sh2Range = Range(.Cells(2, "A"), .Cells(LastRow, "A"))
End With

NewRow = LastRow + 1
For Each cell In Sh1Range
Set c = Sh2Range.Find(what:=cell.Value, LookIn:=xlValues)
If c Is Nothing Then

cell.EntireRow.Copy Destination:=Rows(NewRow)
NewRow = NewRow + 1
End If

Next cell

End Sub


"RyanH" wrote:

This may be an easy one for a VBA guru.

I have to update a production schedule daily by sales order number. I need
to copy and insert non-duplicated rows from Worksheet 2 into Worksheet 1
according to a specific column. For example,

Worksheet 1
Col.A Sales # Col.B Description
1 Description #1
2 Description #2
3 Description #3

Worksheet 2
Col.A Sales # Col.B Description
1 Description #1
4 Description #4
5 Description #5


The macro should only insert the rows with sales # 4 & #5 from Wk Sht. 2 to
Wk Sht 1. Addtionally, the rows should be inserted below the last row with
text in it.

Any help on this would be greatly appreciated! Thank you so much in advance!!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Macro to LookUp Data and Copy/Insert only Non-Duplicated Rows

I think this works! I will double check it manually on our print out of the
schedule. Thank You So Much for such a quick response!!


"Joel" wrote:

try this code

Sub test()

With Sheets("Sheet1")
.Activate
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
Set Sh1Range = Range(.Cells(2, "A"), .Cells(LastRow, "A"))
End With

With Sheets("Sheet2")
.Activate
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
Set Sh2Range = Range(.Cells(2, "A"), .Cells(LastRow, "A"))
End With

NewRow = LastRow + 1
For Each cell In Sh1Range
Set c = Sh2Range.Find(what:=cell.Value, LookIn:=xlValues)
If c Is Nothing Then

cell.EntireRow.Copy Destination:=Rows(NewRow)
NewRow = NewRow + 1
End If

Next cell

End Sub


"RyanH" wrote:

This may be an easy one for a VBA guru.

I have to update a production schedule daily by sales order number. I need
to copy and insert non-duplicated rows from Worksheet 2 into Worksheet 1
according to a specific column. For example,

Worksheet 1
Col.A Sales # Col.B Description
1 Description #1
2 Description #2
3 Description #3

Worksheet 2
Col.A Sales # Col.B Description
1 Description #1
4 Description #4
5 Description #5


The macro should only insert the rows with sales # 4 & #5 from Wk Sht. 2 to
Wk Sht 1. Addtionally, the rows should be inserted below the last row with
text in it.

Any help on this would be greatly appreciated! Thank you so much in advance!!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Macro to LookUp Data and Copy/Insert only Non-Duplicated Rows

I performed the macro and it seemed to work beautifully except the first line
on Sheet 2 is not showing up on Sheet 1. This is the only line not being
inserted, do you know why? Thanks again for all the help!

"Joel" wrote:

try this code

Sub test()

With Sheets("Sheet1")
.Activate
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
Set Sh1Range = Range(.Cells(2, "A"), .Cells(LastRow, "A"))
End With

With Sheets("Sheet2")
.Activate
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
Set Sh2Range = Range(.Cells(2, "A"), .Cells(LastRow, "A"))
End With

NewRow = LastRow + 1
For Each cell In Sh1Range
Set c = Sh2Range.Find(what:=cell.Value, LookIn:=xlValues)
If c Is Nothing Then

cell.EntireRow.Copy Destination:=Rows(NewRow)
NewRow = NewRow + 1
End If

Next cell

End Sub


"RyanH" wrote:

This may be an easy one for a VBA guru.

I have to update a production schedule daily by sales order number. I need
to copy and insert non-duplicated rows from Worksheet 2 into Worksheet 1
according to a specific column. For example,

Worksheet 1
Col.A Sales # Col.B Description
1 Description #1
2 Description #2
3 Description #3

Worksheet 2
Col.A Sales # Col.B Description
1 Description #1
4 Description #4
5 Description #5


The macro should only insert the rows with sales # 4 & #5 from Wk Sht. 2 to
Wk Sht 1. Addtionally, the rows should be inserted below the last row with
text in it.

Any help on this would be greatly appreciated! Thank you so much in advance!!

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
Macro to copy previous row and insert two blank rows dd Excel Programming 1 May 1st 07 01:26 AM
Macro to copy previous row and insert two blank rows dd Excel Discussion (Misc queries) 1 April 30th 07 11:25 PM
Macro that will Cut rows and then insert-copy or append rod Excel Discussion (Misc queries) 3 October 21st 06 04:50 PM
macro to insert rows & copy cells D Hafer - TFE Excel Programming 2 January 8th 06 08:38 PM
Activate a macro to insert a row and copy the formuals from the rows above to the blank row oil_driller Excel Discussion (Misc queries) 1 February 11th 05 03:30 PM


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