am trying to make my code better, so the first thing I am trying to do is to remove all usage of selects and selection from my code.
The problem am facing is I am unable to get a stable code without using Selection. PFB code am using to make the selection
Sub findandCopyVisbleCellsinColumn(ByRef wb As Workbook, ByRef ws As Worksheet, ByRef columnNumber As Long)
Dim lrow, lcolumn As Long
With wb
With ws
ws.Activate
Selection.End(xlToLeft).Select
ws.Range(Cells(1, columnNumber).Address).Offset(1, 0).Select
ws.Range(Selection, Selection.End(xlDown)).Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
End With
End With
End Sub
PFB Code am using for calling above code and pasting the values
emptyCell = range_End_Method(wb, ws, 3)
Call findandCopyVisbleCellsinColumn(wb, ws1, 7)
ws.Range("C" & emptyCell).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
What I have done until now
With ws
ws.Activate
Selection.End(xlToLeft).Select
lrow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
lcolumn = ws.Cells(1, ws1.Columns.Count).End(xlToLeft).Column
.Range(.Cells(.Cells(2, columnNumber).Address).Offset(1, 0), lrow, lcolumn).Copy
End With
this is giving an error for invalid property assignment. I suspect its due to assigning cells to cells, Please point me in the right direction.
Thanks in advance.