code for selecting 2nd visible row

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

After an autofilter I want to select the 2nd visible row and column C and
paste something in there. What is the code for this?

Sheets("Sheet1").Select
Range("C????????").Select
ActiveSheet.Paste
 
One way:

Option Explicit
Sub testme()
Dim myVisRow As Long
Dim myCell As Range
Dim vCtr As Long
Dim WhichVisRow As Long
Dim vRng As Range
Dim wks As Worksheet

Dim SomeRngToCopy as Range

Set wks = ActiveSheet

WhichVisRow = 2
With wks.AutoFilter.Range
'ignore the header and make sure there are
'enough visible rows
If (.Columns(1).Cells.SpecialCells(xlCellTypeVisible).Count - 1) _
< WhichVisRow Then
MsgBox "Not enough visible rows"
Exit Sub
End If

Set vRng = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
.Cells.SpecialCells(xlCellTypeVisible)

vCtr = 0
For Each myCell In vRng.Cells
vCtr = vCtr + 1
If vCtr = WhichVisRow Then
myVisRow = myCell.Row
Exit For
End If
Next myCell

'do your copy and paste
set somerngtocopy = worksheets("somesheetname").range("x99")
somerngtocopy.copy _
destination:=.cells(myvisrow,"C")

End With

End Sub

I assumed that you meant the 2nd visible row of the data--not including the
header.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top