Macro for Button: If Cell = Name then Copy to Another Spreadsheet

koolgeex

New Member
Joined
May 2, 2012
Messages
45
Something like:
In spreadsheet "Complete Backlog", if a cell in Column K = "Open" AND the cell in Column G of the same row = "Snodgress" THEN copy cells A?:J? and paste into cells A?:J? of the "Snodgress" sheet. Of course skipping to the next available row and also the content should not repeat itself.

I have this code so far but it gives me an error about merged cells. I think that's because i have miscellaneous text outside of the designated "paste area". So the whole row shouldn't be pasted, just the specific range. Any suggestions?

Code:
Sub copy_director_snod()
Dim i As Long, lrow As Long, lastrow As Long
With Worksheets("Complete Backlog")
lrow = .Range("a" & .Rows.Count).End(xlUp).Row
For i = 2 To lrow
If .Range("g" & i).Value = "Snodgress" Then
lastrow = Worksheets("Snodgress").Range("A" & Rows.Count).End(xlUp).Row
.Range("A" & i & ":L" & i).Copy Worksheets("Snodgress").Range("A" & lastrow + 1)
a = a + 1
End If
Next i
End With
End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi,

Try this:
Code:
Sub copy_director_snod()
Dim i As Long, lrow As Long, lastrow As Long
With Worksheets("Complete Backlog")
lrow = .Range("A" & .Rows.Count).End(xlUp).Row
For i = 2 To lrow
If   .Range("G" & i).Value = "Snodgress" AND  .Range("K" & i).Value = "Open" Then
lastrow = Worksheets("Snodgress").Range("A" & Rows.Count).End(xlUp).Row
.Range("A" & i & ":J" & i).Copy Worksheets("Snodgress").Range("A" & lastrow + 1)
End If
Next i
End With
 
Upvote 0
Thanks. I received an error that says "Cannot Change Part of a Merged Cell" and it highlights the following line to debug:
Code:
.Range("A" & i & ":J" & i).Copy Worksheets("Snodgress").Range("A" & lastrow + 1)

The only thing that may have merged cells is below row 30 of the Snodgress sheet. So i would need the copied cells to paste into a specific area -- [A2 through A30 only]
 
Upvote 0
Hi,

Not a good idea to use merged cells.

I try in a sheet with merged cells in row 30 and code works well.
Check your sheet
 
Last edited:
Upvote 0
Hm. Okay, so I see that it actually did copy the data but it started pasting in Row 38 for whatever reason. That's why it ran into my formulas and merged cells and such. Any idea why it did that?
 
Upvote 0
They are empty except for the headers in row 1. I do I have validation drop down lists in a few columns though.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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