Create code in VBA that will search through each sheet within the workbook and if the date is equal to today - 1 copy the rows and paste as value

DBarn

New Member
Joined
Jan 7, 2014
Messages
4
Hi, I am new to <acronym title="visual basic for applications">VBA</acronym> - just getting my head around it!! -

I have multiple sheets, the code needs to go through each sheet, look for where the date is equal to today -1, copy the row and past it as values.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
10,592
In what column is the date in each sheet? Where do you want to paste the values?
 

DBarn

New Member
Joined
Jan 7, 2014
Messages
4
In what column is the date in each sheet? Where do you want to paste the values?

My apologies for the little information i gave.
The data is from B15 to V38 and it needs to be paste on the exact same data but as values and not as formulas. It will be the same on each word sheet that i have got except for two sheets that is called, Deals and positions.

Thank you.
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
10,592
Does the copy and paste as values still depend on a cell having the date -1 in it? If so, I need to know the column in which that date is found or can the date be in any cell in the range B15 to V38?
 

DBarn

New Member
Joined
Jan 7, 2014
Messages
4

ADVERTISEMENT

HI mumps, The date and date-1 will always be on column B.
Yes, the copy and paste as value still depend on column B having the date.

Below is how the the sheet looks,

03.12.2013 0.00 595.00- 595.00 18.80- 591.86- 15.66 0.00 0.00 935.44- 935.44
04.12.2013 595.00 595.00 0.00 27.60 27.60 0.00 0.00 0.00 963.04- 963.04
05.12.2013 595.00 635.00- 40.00- 66.50- 114.33- 7.83 0.00 0.00 848.71- 848.71

<tbody>
</tbody>


Thanks for you asssitance
 
Last edited:

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
10,592
Try:
Code:
Sub Test()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim rng As Range
    For Each rng In Range("B2:B" & LastRow)
        If rng = Date - 1 Then
            Rows(rng.Row).Value = Rows(rng.Row).Value
        End If
    Next rng
    Application.ScreenUpdating = True
End Sub
 

Forum statistics

Threads
1,137,062
Messages
5,679,392
Members
419,825
Latest member
MegastarMagus

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
Top