VBA Rows Count Not Resetting

BrainDiseasee

New Member
Joined
Aug 30, 2023
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have written a code to copy a set range from every ws except the ones i exclude. And to start from the bottom and go up to the last cell row with data then offset by one paste values in that destination. Not sure my problem is in my code as i just tried on a blank sheet and it worked as expected. But the problem is after the first set of data pastes, instead of going to the next available row it jumps down by a few hundred rows.

Option Explicit
Sub CopyIt()

Sheets("Project_Hours").Select
Range("A2:E7720").Cells.Clear

Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "Master_Data" And ws.Name <> "Resource_Hours" And ws.Name <> "Chart_01" And ws.Name <> "Project_Hours" And ws.Name <> "Template" And ws.Name <> "PRJ_Table" And ws.Name <> "Team_Dashboard" And ws.Name <> "Archive_Data" Then
ws.Range("B39:F518").Copy
Sheets("Project_Hours").Cells(Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial xlPasteValues

End If
Next
EndSub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Your code as written works for me with my small sample fictitious data. Is it possible that in one of these ranges
VBA Code:
ws.Range("B39:F518").Copy
there are formulas that evaluate to "". Excel will still copy those over and even though they appear to be blank, Excel will evaluate the last row with data at the end of these "blank cells".
 
Upvote 0
Hello,

Thanks for your reply. I actually figured it out kind of. Part of my range was blank cells but for some reason excel wouldnt recognize them as blanks so when i sued Selection.SpecialCells(xlCellTypeBlanks).EntireRow.Delete it wouldnt work i just changed the formulas in the cells to instead of = "" to equal 0 then it removed everything properly.
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,021
Latest member
Justyna P

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