Data pulled from date

culverhr

New Member
Joined
Sep 12, 2011
Messages
2
I am working on creating a production schedule. My main sheet has a date in column B2. If this date is found in another worksheet in say column H, I want it to pull the data from column C to the main spreadsheet. I initially thought a vlookup would work but it is not working out. I only want the data pulled if the date in column H matches the date in the main worksheet column B2. Any ideas???
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Your Main Sheet Before running Macro "Foo" should look like this:
Excel Workbook
ABCDEFGH
1Header ColCHeader ColDHeader ColEHeader ColFHeader ColGHeader ColH
210/15/2011
Main
Excel 2007

Your Sheet2 should look like this:
Excel Workbook
ABCDEFGH
1asdsdfdfgfghghjhj
2My 10/15 StuffXXXYYYZZZXYZ15-Oct
320-Oct
425-Oct
5My 10/15 StuffXXXYYYZZZXYZ15-Oct
615-Nov
7My 10/15 StuffXXXYYYZZZXYZ15-Oct
825-Oct
93-Nov
1015-Nov
Sheet2
Excel 2007

Run this Macro:

Code:
Sub Foo()
firstdate = Sheets("Main").Range("B2")
lastdate = Sheets("Main").Range("B2")
Range("C1:H10").Select
Selection.AutoFilter Field:=6, Criteria1:=">=" & _
firstdate, Operator:=xlAnd, _
        Criteria2:="<=" & lastdate
Set Rng = Range("C2:H7").SpecialCells(xlCellTypeVisible)
Rng.Copy Destination:=Sheets("Main").Range("C2")
End Sub

Now your Main Sheet Afterwards should look like this:
Excel Workbook
ABCDEFGH
1Header ColCHeader ColDHeader ColEHeader ColFHeader ColGHeader ColH
210/15/2011My 10/15 StuffXXXYYYZZZXYZ15-Oct
3My 10/15 StuffXXXYYYZZZXYZ15-Oct
4My 10/15 StuffXXXYYYZZZXYZ15-Oct
Main
Excel 2007
 
Upvote 0
Here's the code - CLEANED-UP ...

Code:
Sub Foo()
Application.ScreenUpdating = False
firstdate = Sheets("Main").Range("B2")
lastdate = Sheets("Main").Range("B2")
Sheets("Sheet2").Activate
Range("C1:H10").Select
Selection.AutoFilter Field:=6, Criteria1:=">=" & _
firstdate, Operator:=xlAnd, _
        Criteria2:="<=" & lastdate
Set Rng = Range("C2:H7").SpecialCells(xlCellTypeVisible)
Rng.Copy Destination:=Sheets("Main").Range("C2")
ActiveSheet.ShowAllData
Sheets("Main").Activate
Application.ScreenUpdating = True
End Sub
 
Upvote 0
It has a problem with the Set Rng = Range("C2:H7").SpecialCells(xlCellTypeVisible), it will not accept.
 
Upvote 0
Sorry, Try This INSTEAD (Replaced code): Jim

Code:
Sub FooX()
Application.ScreenUpdating = False
firstdate = Sheets("Main").Range("B2")
lastdate = Sheets("Main").Range("B2")
Sheets("Sheet2").Activate
Set Rng = Range("C1").CurrentRegion
Rng.AutoFilter Field:=6, Criteria1:=">=" & _
firstdate, Operator:=xlAnd, _
        Criteria2:="<=" & lastdate
Set Rng1 = Rng.Offset(1).Resize(Rng.Rows.Count - 1)
Set Rng1 = Rng1.SpecialCells(xlCellTypeVisible)
'Set Rng1 = Rng.Offset(Rng(1).SpecialCells(xlCellTypeVisible)
Rng1.Copy Destination:=Sheets("Main").Range("C2")
ActiveSheet.ShowAllData
Range("C2").Select
Sheets("Main").Activate
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,822
Members
452,946
Latest member
JoseDavid

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