Results 1 to 6 of 6

Thread: Find cells with today's date and copy asscoiated columns

  1. #1

    Find cells with today's date and copy asscoiated columns



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Hello,


    I have a spreadsheet where various dates are in row
    I require a vba code or macro that will do the following:
    where the date in is today's date. Then copy the selection

    This must be simple but for some reason i am just not getting it!


    Would appreciate any help
    Attached Files Attached Files

  2. #2
    Code:
    Sub CopyData()Dim lastcol As Long
    Dim nextcol As Long
    Dim i As Long
    
    
        With ActiveSheet
        
            lastcol = .Cells(3, .Columns.Count).End(xlToLeft).Column
            For i = 1 To lastcol
            
                If .Cells(3, i).Value = Date Then
                
                    nextcol = nextcol + 1
                    .Range(.Cells(3, i), .Cells(3, i).End(xlDown)).Copy Worksheets("Sheet2").Cells(1, nextcol)
                End If
            Next i
        End With
    End Sub

  3. #3
    problem in the first line

  4. #4
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,284
    Articles
    57
    Blog Entries
    14
    Excel Version
    Excel Office 365 Insider
    Missed a hard return. Try this:

    Code:
    Sub CopyData()
    Dim lastcol As Long
    Dim nextcol As Long
    Dim i As Long
    
    
        With ActiveSheet
        
            lastcol = .Cells(3, .Columns.Count).End(xlToLeft).Column
            For i = 1 To lastcol
            
                If .Cells(3, i).Value = Date Then
                
                    nextcol = nextcol + 1
                    .Range(.Cells(3, i), .Cells(3, i).End(xlDown)).Copy Worksheets("Sheet2").Cells(1, nextcol)
                End If
            Next i
        End With
    End Sub
    Ken Puls, FCPA, FCMA, MS MVP

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training), with my book M is for Data Monkey, or our new Power Query Recipe cards!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  5. #5
    Please can you send me a excel, PLEASE

  6. #6
    Quote Originally Posted by Ken Puls View Post
    Missed a hard return. Try this:

    Code:
    Sub CopyData()
    Dim lastcol As Long
    Dim nextcol As Long
    Dim i As Long
    
    
        With ActiveSheet
        
            lastcol = .Cells(3, .Columns.Count).End(xlToLeft).Column
            For i = 1 To lastcol
            
                If .Cells(3, i).Value = Date Then
                
                    nextcol = nextcol + 1
                    .Range(.Cells(3, i), .Cells(3, i).End(xlDown)).Copy Worksheets("Sheet2").Cells(1, nextcol)
                End If
            Next i
        End With
    End Sub
    ok. I found it. THANKS

Posting Permissions

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