VBA Question for Range on open ended Columns

arossijr

Board Regular
Joined
Aug 29, 2016
Messages
72
I used the Macro Recorder to get the basics, added in for Criteria1 and Criteria2... All worked good till I needed to select certain rows and available cells...
Here is the code I am using with all the "Failures" for selecting the ranges..

Application.ScreenUpdating = False
Dim Startdate, EndDate As Date
Dim LngLastRow As Long



Any and all help welcome!!! Thank you!!!



Startdate = Sheets("Data").Range("B1").Value
EndDate = Sheets("Data").Range("B2").Value


Range("A4").Select
Selection.End(xlDown).Select
LngLastRow = ActiveCell.Row




'ActiveSheet.ListObjects("Data").Range.AutoFilter Field:=1, Operator:= _
'xlFilterValues, Criteria2:=Array(1, "5/31/2018")
'ActivateSheet.ListObjects("Data").Range.AutoFilter Field:=1, Criteria1:=">=" & Startdate, Operator:=xlAnd, Criteria2:="<=" & EndDate
Sheets("Data").ListObjects("Data").Range.AutoFilter Field:=1, Criteria1:=">=" & Startdate, Operator:=xlAnd, Criteria2:="<=" & EndDate

'ActiveWindow.SmallScroll Down:=9
'Range("A4:A108,B4:B108,C4:C108,G4:G108,I4:I108,J4:J108").Select
'Sheets("Data").Range("A4", "B4", "C4", "G4", "I4", "J4").Select
'Sheets("Data").Range(A.Address, B.Address, C.Address, G.Address, I.Address, J.Address).Select
'Sheets("Data").Range("A4,B4,C4,G4,I4,J4").Select
Sheets("Data").Range("A4" & LngLastRow, "B4" & LngLastRow, "C4" & LngLastRow, "G4" & LngLastRow, "I4" & LngLastRow, "J4" & LngLastRow).Select
'Range("J2").Activate
'Sheets("Data").ListObjects("Data").AutoFilter.Range.Copy
Selection.SpecialCells(xlCellTypeVisible).Copy
Sheets("Report").Select
Range("Table1[DATE]").Select
ActiveSheet.Paste
End Sub
 
Last edited:
Code:
Option Explicit


Sub Test()


' Test Macro2
Application.ScreenUpdating = False
Dim tbl As ListObject
Dim tbl2 As ListObject
Dim Rng As Range
Dim Rng2 As Range
Dim Rng3 As Range
Dim Rng4 As Range
Dim StartDate, EndDate As Date
Dim LastRow As Long
Dim Rpt As Worksheet


StartDate = Sheets("Data").Range("B1").Value
EndDate = Sheets("Data").Range("B2").Value


Set tbl = Sheets("Data").ListObjects("Data")
Set tbl2 = Sheets("Report").ListObjects("Report")
Set Rng = tbl.DataBodyRange
Set Rng2 = tbl2.DataBodyRange
Set Rng3 = Sheets("Data").Range("Data[Date],Data[Loc],Data[Acct],Data[Part '#],Data[Qty Sold],Data[Base]")
Set Rng4 = Sheets("Report").Range("Report[Date],Report[Loc],Report[Acct],Report[Part '#],Report[Qty Sold],Report[Base]")
Set Rpt = Sheets("Report")




tbl.Range.AutoFilter Field:=1, Criteria1:=">=" & StartDate, Operator:=xlAnd, Criteria2:="<=" & EndDate


Rng3.Select


Selection.Copy
Rpt.Select
Range("A2").Select
ActiveSheet.Paste




End Sub
[Code/]
 
Last edited:
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Did you try the script I provided?
Did it work?
Do you still need more help or are you now OK
 
Upvote 0

Forum statistics

Threads
1,216,082
Messages
6,128,713
Members
449,464
Latest member
againofsoul

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