reyramirez27
New Member
- Joined
- May 18, 2022
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
This is a copy macro that copies down based on user input from a pop up box. The issue is that when the excel sheet is filtered it will copy the filtered out data. How can this be modified to only count visible cells? Appreciate the assistance.
Public Function CSOfSelection() As String
Dim sOut As String
Dim i As Integer
Dim area
Dim cell
Dim iRows As Variant
iRows = InputBox("Enter number of rows:")
If IsNumeric(CInt(iRows)) = False Then
Exit Function
Else
iRows = CInt(iRows)
End If
Range(Cells(ActiveCell.Row, ActiveCell.Column), Cells(ActiveCell.Row + iRows - 1, ActiveCell.Column)).Copy
ActiveWindow.SmallScroll down:=iRows - 3
'First check to see if there is a valid FN in the active Workbook selected
If Not ActiveWorkbook Is Nothing Then
If TypeOf Selection Is Excel.Range Then
For Each area In Selection.Areas
For Each cell In area
sOut = sOut & cell.Value & "," ''This can be changed to fit whatever functions you need for the data in the selection
Next cell
Next area
End If
End If
sOut = Left(sOut, Len(sOut) - 1) ''This chops off the trailing comma
CSOfSelection = sOut
End Function
Public Function CSOfSelection() As String
Dim sOut As String
Dim i As Integer
Dim area
Dim cell
Dim iRows As Variant
iRows = InputBox("Enter number of rows:")
If IsNumeric(CInt(iRows)) = False Then
Exit Function
Else
iRows = CInt(iRows)
End If
Range(Cells(ActiveCell.Row, ActiveCell.Column), Cells(ActiveCell.Row + iRows - 1, ActiveCell.Column)).Copy
ActiveWindow.SmallScroll down:=iRows - 3
'First check to see if there is a valid FN in the active Workbook selected
If Not ActiveWorkbook Is Nothing Then
If TypeOf Selection Is Excel.Range Then
For Each area In Selection.Areas
For Each cell In area
sOut = sOut & cell.Value & "," ''This can be changed to fit whatever functions you need for the data in the selection
Next cell
Next area
End If
End If
sOut = Left(sOut, Len(sOut) - 1) ''This chops off the trailing comma
CSOfSelection = sOut
End Function