Macro to copy data if date is ...

MagicMrMiyagi

New Member
Joined
Sep 24, 2010
Messages
18
Good morning everybody,

I am trying to create a macro that copies data from one worksheet into another. So far I am using code like this:

Code:
Sub LogCost()
Dim sPlant As String
Dim sBU As String
sPlant = Range("q5").Text
sBU = "Green"
Application.ScreenUpdating = False
 
Windows("Gifts.xlsm").Activate
With Workbooks("Gifts.xlsm").Sheets("Today")
For i = 1 To 400
'YTDActual
If .Range("I" & i) = sPlant And .Range("G" & i) = sBU Then
.Range("C" & i).Copy
actual = 7
Workbooks("Action.xlsm").Sheets("Action_Today").Activate
Cells(actual, "N").End(xlToLeft).Offset(0, 1).PasteSpecial Paste:=xlPasteValues
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
 
End If
Next i
End with
End sub

This works as long as I have only two conditions, stated by may variables.

Now I am having a problem trying to copy different data, depending on the actual quarter.

For example column A contains Data for Q1 (January,February, March), column B contains Data for Q2 (April, May, June) and so on.
The actual month is on the same sheet where I am getting the data from in cell "BD2".

So i figured it has to be something like (careful wrong and silly code incoming ;) )
Code:
if .cells("BD2") = "01.01.2011" or cells.("BD2") = "01.02.2011" or cells ("BD2") = "01.03.2011" Then
.Range("A" & i).Copy
end if
if .cells("BD2") = "01.04.2011" or cells.("BD2") = "01.05.2011" or cells ("BD2") = "01.06.2011" Then
.Range("B" & i).Copy

Obviously that bit of code is not working but I hope that it helps to see what I am trying to do.

I hope that it didn't get too confusing and that someone can help me.

Thanks in advance

Fred
 
Last edited:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,224,508
Messages
6,179,189
Members
452,893
Latest member
denay

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