Odd Error When Copying Filtered Data

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
714
Office Version
  1. 365
Platform
  1. Windows
I have the following snippet of code that is giving me trouble. Essentially, I'm filtering for the word "Keep" earlier in the code. That works. The below snippet identifies sDLR and mNLR + 1 correctly. However, if there is only 1 record with "Keep" and that record is in row 2, the code is trying to copy all of rows 1 & 2. In trying to figure out the issue, I found that if I move the record with "Keep" to row 5, the code runs as expected.

VBA Code:
With sD.Range("B2:B" & sDLR).SpecialCells(xlCellTypeVisible).Copy
    mN.Range("H" & mNLR + 1).PasteSpecial (xlPasteValues)
End With

Thoughts?
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
If sDLR is 2, then you are applying specialcells to one cell only, which has the effect of applying it to the used range of the worksheet. You'll want to test for that case specifically.
 
Upvote 1
Solution
If sDLR is 2, then you are applying specialcells to one cell only, which has the effect of applying it to the used range of the worksheet. You'll want to test for that case specifically.
@RoryA I was having the same issue with a different snippet. This appears to work, but I'm curious if there's a cleaner/more efficient way to go about it.
VBA Code:
If mNLR = mN.Range("C2").Row Then
    mN.Range("N2").Value = "N/A"
Else
    mN.Range("N2:N" & mNLR).SpecialCells(xlCellTypeVisible).Value = "N/A"
End If
 
Upvote 0

Forum statistics

Threads
1,223,967
Messages
6,175,672
Members
452,666
Latest member
AllexDee

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