Copy the range below to another location, but ignoring the blank rows

Guinaba

Board Regular
Joined
Sep 19, 2018
Messages
218
Office Version
  1. 2016
Platform
  1. Windows
Hi guys,

I need to copy the range below to another location, but ignoring the blank rows. Any suggestions? The blank rows vary depending whether the formulas in there bring or not values.


Roast BirdsState variance +/-10%
This week at 596t, -110t down vs DP. 7t drop from yesterdayQLDNSWVICSAWATASNT
84%85%86%83%87%80%77%
Woolworths Deli: Top 5 positive and negative variances greater or less than 3tState variance +/-10%
Positive VariancesVariance to DPQLDNSWVICSAWATASNT
1511300​
BREAST FILLETS 12KG6t above DP127%91%102%110%104%78%88%4t drop from yesterday.
3415800​
F/RANGE CHICKEN 1.45KGX86t above DP106%104%113%100%112%90%100%2t drop from yesterday.
Negative VariancesQLDNSWVICSAWATASNT
1364100​
DRUMSTICKS 12KG12t below DP93%91%95%94%89%80%81%8t drop from yesterday.
Woolworths Meat: Top 7 positive and negative variances greater or less than 3t
Positive VariancesQLDNSWVICSAWATASNT
1820500​
F/RANGE THIGH FILLET RWX123t above DP115%117%108%117%109%93%110%
3159200​
LE/HERB BLESS BFLYCHICKEN RWX63t above DP91%105%105%105%180%165%92%
Negative VariancesQLDNSWVICSAWATASNT
1593500​
BREAST FILLETS RWX810t below DP94%95%92%90%89%74%104%1t drop from yesterday.
1557300​
F/RANGE BREAST FILLET LGE RWX86t below DP87%90%85%93%96%67%90%2t drop from yesterday.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi

So since you haven’t had a response on this I could think of a couple of ways forward for you.

1, create a loop to check if row is empty. If empty move on etc. otherwise copy the row.

2, use a helper column with formula to determine if there is data in the row. Then filter the range by the helper column, copy and paste the filtered data.

Am happy to assist with either of the above.
My response may bump your post for someone else to make suggestions.

Upon posting your reply , if you could supply the row and column at where your data starts and possibly ends.

Also please tell us the location you want the data to go to.

Dave.
 
Upvote 0
Thanks @SQUIDD for anwering! You gave me a really good suggestion and I ended up adopting both :)
1) create a loop to check if row is empty
2) use a helper column with formula to determine if there is data in the row

So in my range now I have the first col. having 1 or 0. If 1 then copy, 0 delete the entire row, however not sure why my code is not deleting the rows with 0:

VBA Code:
Dim c As Integer
Dim r As Integer
    
   'loop though the array
    For c = LBound(CurrWkArr4, 2) To UBound(CurrWkArr4, 2)
        For r = LBound(CurrWkArr4, 1) To UBound(CurrWkArr4, 1)
            If CurrWkArr4(r, 1) = 1 Then
               CurrWkWB.Worksheets("Test").Cells(r, c).Value = CurrWkArr4(r, c) 'Copy the data from Arr back to sheet (Test)
               Else
               CurrWkArr4(r, c).EntireRow.Delete ' Delete the entire row
            End If
        Next r
    Next c
 
Upvote 0
Hi.

I’m not at my pc right now.
But in my experience, when deleting rows I have always changed my for loop to delete rows from bottom to top.

So for example

For a = 100 to 1 step -1

Will be at my pc in a couple of hours.

Also, cannot see you have specified CurrWkArr4 as anything ?

Dave.
 
Upvote 0
Also would the below not delete the row by row number ?

Rows(r).EntireRow.Delete
 
Upvote 0
Also would the below not delete the row by row number ?

Rows(r).EntireRow.Delete
Hi @SQUIDD,

Thanks for tip about the reverse loop. Amost there :), rather than looping and deleting the rows when copying, I've found that it is faster just copying the entire range and after that delete the rows flagged with "N".

However, not sure what is wrong with my logic, because my reverse loop in deleting only the last empty row in the range and stop looping afterwards, it should keep looping backwards...

VBA Code:
    For r = LastRow To Worksheets("EmailFormat").Range("B2") Step -1    
        If Worksheets("EmailFormat").Range("B" & r) = "N" Then
           Worksheets("EmailFormat").Range("B" & r).EntireRow.Delete
        End If 
    Next r



1638139865045.png
 
Upvote 0
Hi

So in your 1st line of code

VBA Code:
For r = LastRow To Worksheets("EmailFormat").Range("B2") Step -1

with this bit

VBA Code:
Worksheets("EmailFormat").Range("B2")

You are looping down to the value of this cell?

I would suggest the below on the assumption you data starts at row 2 and you have headers.

VBA Code:
For r = LastRow To 2 Step -1
    If Range("'EmailFormat'!B" & r) = "N" Then Range("'EmailFormat'!B" & r).EntireRow.Delete
Next r





Dave
 
Upvote 0
Solution
Hi

So in your 1st line of code

VBA Code:
For r = LastRow To Worksheets("EmailFormat").Range("B2") Step -1

with this bit

VBA Code:
Worksheets("EmailFormat").Range("B2")

You are looping down to the value of this cell?

I would suggest the below on the assumption you data starts at row 2 and you have headers.

VBA Code:
For r = LastRow To 2 Step -1
    If Range("'EmailFormat'!B" & r) = "N" Then Range("'EmailFormat'!B" & r).EntireRow.Delete
Next r





Dave
Hi

So in your 1st line of code

VBA Code:
For r = LastRow To Worksheets("EmailFormat").Range("B2") Step -1

with this bit

VBA Code:
Worksheets("EmailFormat").Range("B2")

You are looping down to the value of this cell?

I would suggest the below on the assumption you data starts at row 2 and you have headers.

VBA Code:
For r = LastRow To 2 Step -1
    If Range("'EmailFormat'!B" & r) = "N" Then Range("'EmailFormat'!B" & r).EntireRow.Delete
Next r





Dave
Awesome @SQUIDD !! Thanks Dave! It worked like a charm!!
 
Upvote 0
Great. Glad it’s all working for you.

You nearly got there yourself.

Good job.

Dave.
 
Upvote 0

Forum statistics

Threads
1,215,422
Messages
6,124,808
Members
449,191
Latest member
rscraig11

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