Paste Values Into Next Blank Row

davisshannon

New Member
Joined
Jun 20, 2018
Messages
16
Hi,

I have a workbook with multiple sheets where I'm trying to copy rows where the value in column C > 0. I then want to paste these rows into a another sheet, called BoM. I'm ignoring the BoM sheet, along with a sheet called summary, and another sheet called Packet Storage.

I'm got my code partially working, but I'm having trouble getting the rows from each subsequent sheet to begin pasting on the next available row. I can loop through each sheet, but then the next sheet just starts pasting at the top again overwriting the last sheet's data. I'm also getting the row headers from each sheet pasted into the destination sheet, which would be ok the first time, but I don't want that from each sheet thereafter.

I'm sure there's a bit of ugliness in my code here (I'm a networking guy), so be nice. Thanks for your help on this in advance.

Here's my code:

Sub CopyRow()

For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "BoM" And ws.Name <> "Summary" And ws.Name <> "Packet Storage" Then
ws.Activate
Dim LastRow As Long
Dim x As Long
Dim rng As Range
x = 1

For Each rng In ActiveSheet.Range("C:C")
If rng > 0 Then
rng.EntireRow.Copy
With Sheets("BoM").Cells(x, 1)
.PasteSpecial xlValues
.PasteSpecial xlFormats
End With
x = x + 1
End If
Next rng
End If
Next


Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub
 
In your original post you said:

If ws.Name <> "BoM" And ws.Name <> "Summary" And ws.Name <> "
Packet Storage
" Then

But in your last post you said:

Packet Capture
<strike>
</strike>
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
My original script works ok, but it just needs to paste into the next available row. My brain starts hurting a bit working through the loops to get this to happen. Does anyone have any ideas?

Thanks
 
Upvote 0
And that is happening.

Look at the script and you will see that line of code. Change those sheet names if they are wrong.

If it's still not doing what you want.
Someone else here at Mr. Excel will I'm sure be able to help you.

What exactly now is it doing wrong?
 
Upvote 0
Thanks for your help. Yeah, the sheet names are fine, but for some reason it's grabbing data from the Packet Storage sheet (last one in the workbook), and the image from column B somewhere (most sheets have the same image in that column).

I'll see if someone else comes back with anything, but thank you very much for trying to help me out.

And that is happening.

Look at the script and you will see that line of code. Change those sheet names if they are wrong.

If it's still not doing what you want.
Someone else here at Mr. Excel will I'm sure be able to help you.

What exactly now is it doing wrong?
 
Upvote 0
OK:
I still suspect the sheet name itself is not:
Packet Storage

Or the name shown in the script is not correct.

These names must be exact including spaces.

This is beyond my knowledgebase.
I will continue to monitor this thread to see what I can learn.
 
Upvote 0
Thanks. Yeah, I've checked the name a few times. And the image doesn't exist in that sheet. My script used to copy stuff from Packet Storage until I put that line in to ignore it, and then it worked ok, except for the overwriting line issue.
 
Upvote 0
Here is a test to see if your sheet names are correct:

Run this script.

If you get a error it's because your sheet names are not correct.
Code:
Sub Test_Me()
Sheets("BoM").Activate
Sheets("Summary").Activate
Sheets("Packet Storage").Activate
    
End Sub
 
Upvote 0
Yep, those sheets come back fine with that test, so the name is ok. Not sure why it's grabbing data from Packet Storage (the very last sheet), along with an image from B2 in another sheet (most have the same image), where C2 in every row is a blank cell?

Does anyone else have any ideas on how to just get this pasting loop working without overwriting the previous sheet's data?
 
Upvote 0
I do not know what to say.
I have tested the script and it works for me.

I have asked and I'm not sure if you has answered.
Is everything working properly except for pulling in data from wrong sheet.

As far as images. I don't understand what type images you have. I guess if you have image attached to row then when it copies row to Master sheet it would copy in the image.

And if you have formulas in sheet Mom for example that refer to a row in sheet you not want to pull data in from the value would be pulled in because of the formula pulling in the data from the sheet you do not want to pull data in from.

What sort of data is in these rows.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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