Pasting text on Visible range error

rex759

Well-known Member
Joined
Nov 8, 2004
Messages
536
Hello,

The goal of the snippet below is to filter out the rows that do not meet the criteria and add the acronym of “HDP” in column F for the visible rows. If I step through using F8, it works as expected. If run it using F5, is pastes the acronym “HDP” starting with the row past the visible range for another 2000 rows. The workbook has many tabs and the input page is 2000 rows. It seems like its picking up the range on the Input tab. I can add code to clear the contents if needed but not sure why its picking up the range of another sheet.

VBA Code:
Dim Xrow As Long, dng As Range
With newSheet
Xrow = Cells(Rows.Count, "A").End(xlUp).Row

'This is the Column to paste "HDP"
Set dng = .Range("F2:F" & Xrow)
'Filter out just stores that start with a 2 or 3
.Range("a1:G1").AutoFilter Field:=3, Criteria1:= _
"=inventory - 2****", Operator:=xlOr, Criteria2:="=inventory - 3****"

If Range("a1:a" & Xrow).SpecialCells(xlCellTypeVisible).Count < 2 Then
  GoTo 77
End If

'Filter out store that don’t have cycle count.
.Range("A1:G1" & Xrow).AutoFilter Field:=4, Criteria1:="cycle count audit"

If .Range("a1:a" & Xrow).SpecialCells(xlCellTypeVisible).Count < 2 Then
    GoTo 77
End If

'Paste HDP in visbile cells
dng.SpecialCells(xlCellTypeVisible) = "HDP"
End With
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,883
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
Dim Xrow As Long, dng As Range
With NewSheet
   Xrow = .Cells(Rows.Count, "A").End(xlUp).Row
   
   'This is the Column to paste "HDP"
   Set dng = .Range("F2:F" & Xrow)
   'Filter out just stores that start with a 2 or 3
   .Range("a1:G1").AutoFilter Field:=3, Criteria1:= _
      "=inventory - 2****", Operator:=xlOr, Criteria2:="=inventory - 3****"
     
   'Filter out store that don’t have cycle count.
   .Range("A1:G1" & Xrow).AutoFilter Field:=4, Criteria1:="cycle count audit"
   
   If .Range("a1:a" & Xrow).SpecialCells(xlCellTypeVisible).Count > 1 Then
      .AutoFilter.Range.Offset(1).Columns(6).Resize(Xrow - 1).Value = "HDP"
   End If
End With
 
Solution

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,883
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.

For future reference when Marking as solution, you need to select the post that helped the most, not your post saying it works. I have changed it for you this time.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,172
Messages
5,640,580
Members
417,151
Latest member
ChickenTenderer

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
Top