+ Reply to Thread
Results 1 to 8 of 8

Ammendment to working code

Hybrid View

  1. #1
    Registered User
    Join Date
    10-25-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    65

    Ammendment to working code

    Hello forum users,

    I am currently using the following code which works perfectly:
    Sub findtoday()
    
    Dim lr As Long
    Dim rcell As Range
    
    lr = Cells(Rows.Count, 20).End(xlUp).Row
    
    For Each rcell In Range("T3:T" & lr)
    
        If rcell = Date Then
        
            Range(rcell, rcell.Offset(, 48)).Copy Sheets("Paste").Range("T" & Rows.Count).End(3)(2)
            
        End If
        
    Next rcell
    
    End Sub
    The code finds cells with Today's date from a column T in one spreadsheet
    copies those cells and 48 cells next to them i.e columns T to BP where Today's date is in T
    And pastes those onto another spreadsheet called "Paste".

    I need to amend the code slightly so that it finds the cells with Today's date in T but copies from column V to BP or in other words (BP is 45 cells to the right of V) and pastes that in the sheet "Paste"

    I no longer need to paste the cells from column T or U where Today's date is in T.

    I hope this makes sense. Can anyone help!
    Last edited by paulary30; 01-03-2013 at 12:18 PM.

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Ammendment to working code

    Sounds easy enough...

    Sub findtoday()
    
    Dim lr As Long
    Dim rcell As Range
    
    lr = Cells(Rows.Count, 20).End(xlUp).Row
    
    For Each rcell In Range("T3:T" & lr)
    
        If rcell = Date Then
        
            Range(rcell.EntireRow.Cells(22), rcell.EntireRow.Cells(68)).Copy Sheets("Paste").Range("T" & Rows.Count).End(3)(2)
            
        End If
        
    Next rcell
    
    End Sub
    Last edited by Andrew-R; 01-03-2013 at 11:45 AM. Reason: Typo ... again!

  3. #3
    Registered User
    Join Date
    10-25-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    65

    Re: Ammendment to working code

    Hello Andrew,

    Thanks for replying

    I gave the wrong code to begin with. I should have put
    Sub Copytodaylib()
    
    Sheets("DISTRACTIONS").Select
    Dim lr As Long
    Dim rcell As Range
    
    
    lr = Cells(Rows.Count, 20).End(xlUp).Row
    
    
    For Each rcell In Range("T2:T" & lr)
    
    
        If rcell = Date Then
        
            Range(rcell, rcell.Offset(, 48)).Copy
            With Sheets("Paste").Range("A" & Rows.Count).End(xlUp).Offset(1)
            .PasteSpecial Paste:=xlPasteColumnWidths
            .PasteSpecial Paste:=xlPasteValues
            End With
           
        End If
        
    Next rcell
    
    End Sub
    However I put
    Range(rcell.EntireRow.Cells(22), rcell.EntireRow.Cells(68)).Copy
    from the code you gave me to replace
    Range(rcell, rcell.Offset(, 48)).Copy
    on my code and it worked so thanks very much.


  4. #4
    Registered User
    Join Date
    10-25-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    65

    Re: Ammendment to working code

    Where do I go to mark this thread as solved?

  5. #5
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Ammendment to working code

    Happy to help and glad you're sorted.

    To mark your thread solved do the following:
    - Go to the first post
    - Click edit
    - Click Advance
    - Just below the word "Title:" you will see a dropdown with the word No prefix.
    - Change to Solve
    - Click Save

  6. #6
    Registered User
    Join Date
    10-25-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    65

    Re: Ammendment to working code

    Done, thanks

    I have another question - do I have to start a new thread?

  7. #7
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Ammendment to working code

    If the question is related to the same problem then you can post it in this one.

    However, fewer people are likely to click on a thread marked 'Solved' which already has a number of replies, so you'll probably attract more views if you start a new thread.

  8. #8
    Registered User
    Join Date
    10-25-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    65

    Re: Ammendment to working code

    OK - it is a different question so i'll post it to another thread

    Thanks for your help

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1