Select a column with Varying data (VBA)

O177812

Board Regular
Joined
Apr 16, 2015
Messages
82
Office Version
  1. 365
  2. 2021
I have constructed the following:

Workbooks.Open Filename:= _
"P:\word documents\INW Group\WORKING\Shipping_Data.xlsx"
Columns("A:Z").Select
Selection.EntireColumn.Hidden = False
Range("V1").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$V$500").AutoFilter Field:=22, Criteria1:="<>"
Windows("Shipping_Data.xlsx").Activate
Range("V2:V77").Select
Selection.Copy
Windows("SO Tracking.xlsx").Activate
Range("C2").Select
ActiveSheet.Paste
Range("B2").Select
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("B2:B16")
Range("B2:B16").Select
Windows("Shipping_Data.xlsx").Activate
ActiveWindow.LargeScroll ToRight:=-1
Range("B2:B77").Select
Selection.Copy
Windows("SO Tracking.xlsx").Activate
Range("A2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
End Sub

However I need to incorporate a function, possibly .End(xlDown), because the data varies day by day and I don't want the end of the selection limited. I want it to select to the end of the data in that column.

Any help would be appreciated.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Trying to decipher your code, here would be the beginning set up and possible the first copy/paste part of the code.
The assumption is workbook "SO Tracking.xlsx" is already open.


VBA Code:
    Dim bk As Workbook, sh As Worksheet
    Dim wb As Workbook, ws As Worksheet, rng1 As Range
    Set wb = Workbooks("SO Tracking.xlsx")
    Set ws = wb.Sheets("Sheet1")'change sheet name if required
    Set rng1 = ws.Range("C2")'set first range to paste

    Set bk = Workbooks.Open("P:\word documents\INW Group\WORKING\Shipping_Data.xlsx")
    Set sh = bk.Sheets("Sheet1")
    sh.Columns("A:Z").EntireColumn.Hidden = False
    sh.Range("A1").AutoFilter Field:=22, Criteria1:="<>"
    bk.Range("V2:V" & Cells(Rows.Count, "V").End(xlUp).Row).Copy Destination:=rng1
 
Upvote 0
Trying to decipher your code, here would be the beginning set up and possible the first copy/paste part of the code.
The assumption is workbook "SO Tracking.xlsx" is already open.


VBA Code:
    Dim bk As Workbook, sh As Worksheet
    Dim wb As Workbook, ws As Worksheet, rng1 As Range
    Set wb = Workbooks("SO Tracking.xlsx")
    Set ws = wb.Sheets("Sheet1")'change sheet name if required
    Set rng1 = ws.Range("C2")'set first range to paste

    Set bk = Workbooks.Open("P:\word documents\INW Group\WORKING\Shipping_Data.xlsx")
    Set sh = bk.Sheets("Sheet1")
    sh.Columns("A:Z").EntireColumn.Hidden = False
    sh.Range("A1").AutoFilter Field:=22, Criteria1:="<>"
    bk.Range("V2:V" & Cells(Rows.Count, "V").End(xlUp).Row).Copy Destination:=rng1

I recieved the following error on the last line:

1658353577115.png


It won't copy and paste
 
Upvote 0
Should be,
VBA Code:
sh.Range("V2:V" & Cells(Rows.Count, "V").End(xlUp).Row).Copy Destination:=rng1
 
Upvote 0
Or maybe
VBA Code:
sh.Range("V2:V" & sh.Cells(Rows.Count, "V").End(xlUp).Row).Copy Destination:=rng1
 
Upvote 0

Forum statistics

Threads
1,215,008
Messages
6,122,672
Members
449,091
Latest member
peppernaut

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
Back
Top