DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Excel macro - copy data between worksheets if certain criteria is met

  1. #1
    Join Date
    Jul 2006

    Question Excel macro - copy data between worksheets if certain criteria is met

    Hello there,
    I'm new to macros & have thrown myself in the deep end.

    I've got an "INPUT" worksheet, where cell "E1" contains a date that i want to change manually. Data gathered for a particular date is typed in under ~20 columns, each labelled with codes such as "C15", "C16". These codes are located in the Range("E2:Z2")

    There will be separate worksheets, one for each code, each containing a row of dates at the top.

    Is there a way of copying column data from the "INPUT" worksheet to the individual code worksheets (eg "C15", "C16" etc) under the correct date column?


  2. #2
    Join Date
    Jul 2006
    This is where I'm at so far:

    Sub Just_Do_It_2()
    Dim Input_Date As Variant
    Dim i As Integer

    Input_Date = Worksheets("input").Range("E1").Value

    For i = 0 To 248
    ' Checks row of dates in worksheet C15 for a match to the Input_Date
    ' If there is a match, it copies Range E4:E300 from input sheet
    ' to the column with the correct date in Worksheet C15

    If Worksheets("C15").Range("E2").Offset(0, 0 + i).Value = Input_Date Then
    Worksheets("Input").Range("E4:E300").Copy _
    Worksheets("C15").Range("E4").Offset(0, 0 + i)

    'I want to be able to do the above If condition for Worksheet("C16")
    'but the Range to be copied will now be "F4:F300".
    'For every worksheet (20 of them), the range to be copied will increment in column by 1
    'Also, is there a way to match the worksheet name with identical column headings which i have located in this row:
    ' Worksheets("input").Range("E2")

    End If
    Next i

    End Sub

    I've attached a print screen of the worksheets i'm working between at the moment.

    Any guidance would be appreciated!
    Attached Images Attached Images

  3. #3
    Join Date
    Aug 2005
    Best suggestion I ever got regarding Excel macros is this:

    From the menu, select Tools, Macro, Record New Macro.
    Then do manually what you would like the macro to do.
    Stop macro recording.
    Edit macro to see code that was written for you [this is where you can add your conditional statement].

Similar Threads

  1. Export to excel data from ultrawebgrid rows
    By sunilmskr in forum ASP.NET
    Replies: 1
    Last Post: 06-10-2005, 09:29 AM
  2. Excel using data from Access
    By Ron Weller in forum VB Classic
    Replies: 0
    Last Post: 04-15-2005, 11:15 PM
  3. Re: maintaining data when importing into excel
    By denis pelletier in forum XML
    Replies: 8
    Last Post: 08-08-2002, 09:02 PM
  4. Data Junction Announces XML Junction 7.51
    By Tim Frost in forum xml.announcements
    Replies: 0
    Last Post: 04-02-2001, 10:53 AM
  5. Accessing Excel Data via ADO
    By Martin Danner in forum authorevents.vaughn
    Replies: 3
    Last Post: 05-31-2000, 05:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center