How to avoid using SELECT and ACTIVATE?

shilos_dad

New Member
Joined
Mar 20, 2019
Messages
2
i have written this piece of code below, but a friend suggested i avoid using activate and select.
i tried re-writing by using WITH but it is not working. what can you guys suggest? thanks.


wb2.Activate
ws1.Activate
rngA.Select
Range(rngA, ActiveCell.End(xlDown)).Select
Selection.Copy
 

Some videos you may like

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,110
Office Version
  1. 365
Platform
  1. Windows
Hi. Try like this:

Code:
Sub test()

Dim wb2 As Workbook, ws1 As Worksheet, rngA As Range

Set wb2 = ThisWorkbook
Set ws1 = wb2.Sheets("Sheet1")
Set rngA = ws1.Range("A1")

Range(rngA, rngA.End(xlDown)).Copy

End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,108,970
Messages
5,525,965
Members
409,673
Latest member
Riseee

This Week's Hot Topics

Top