+ Reply to Thread
Results 1 to 5 of 5

Copypaste after conditions are met

  1. #1
    Registered User
    Join Date
    07-10-2015
    Location
    Glasgow, UK
    MS-Off Ver
    2013
    Posts
    3

    Copypaste after conditions are met

    Hey Guys,

    I am fairly new to VBA. I am trying to create a code that will help me do the following.

    If Cells in column C have an interior colour of grey and if the cells in Column D have a value more than zero,
    the value of the cell in column C will be copied and paste onto a separate sheet.

    This is what I have come up with: (Its definitely wrong)

    For i= 1 to 100
    if (cells(c,i).Interior.Pattern = xlSolid.PatternColorIndex = xlAutomatic.ThemeColor = xlThemeColorDark1.TintAndShade = -0.249977111117893 .PatternTintAndShade = 0)
    and (cells(d,i) > 0) then
    Range("C").CopySheets("Sheet2").SelectRange("A1").Paste
    end if
    end sub

    There are a thousand syntax errors within what I am trying to develop. If anyone could recommend me a book such that I can learn the structure of the programming language or point me to how to solve this problem, it would really be awesome.

    I have attached my trial sheet if it helps.

    Thank you very much!

    mylittleproject.xlsx

  2. #2
    Forum Contributor LokeshKumar's Avatar
    Join Date
    03-31-2015
    Location
    India
    MS-Off Ver
    All, mostly 2010 now..
    Posts
    471

    Re: Copypaste after conditions are met

    Please read..
    Excel 2003 Power Programming with VBA
    Lokesh Kumar
    Stay Hungry.. Stay Foolish..
    _________________________________________________________
    Please Click STAR to Add Reputation if my/someone's answer helped!

  3. #3
    Registered User
    Join Date
    07-10-2015
    Location
    Glasgow, UK
    MS-Off Ver
    2013
    Posts
    3

    Re: Copypaste after conditions are met

    Okay managed to read the book and get an idea of the syntax.

    Cheers!
    This is macro I developed. It works fantastic, bar one problem which is that it populates the data on the new sheet in the order of which it meets the conditions. I.e if item 11 and 60 meet the conditions then cells 11 and 61 are filled as opposed to cells 1 and 2. I have tried some ways to rectify this including using ranges but it doesn't work. Any ideas?

    The macro is as follows:

    Private Sub CommandButton1_Click()
    Dim items As String
    Dim item_value As String
    Dim dates As Date
    Dim checklist As String
    Dim i As Integer
    For i = 1 To 100
    items = Cells(i, 3).Interior.Color
    item_value = Cells(i, 3).Value
    dates = Cells(i, 4).Value
    If items <> vbYellow And dates > 0 Then
    checklist = item_value
    Worksheets(2).Cells(i, 1).Value = checklist
    End If
    Next i
    End Sub

    I have attached the project file for anyone who ever needs a reference.
    Attached Files Attached Files

  4. #4
    Forum Contributor LokeshKumar's Avatar
    Join Date
    03-31-2015
    Location
    India
    MS-Off Ver
    All, mostly 2010 now..
    Posts
    471

    Re: Copypaste after conditions are met

    Could you please marked it solved if you do not have any further query.

  5. #5
    Registered User
    Join Date
    07-10-2015
    Location
    Glasgow, UK
    MS-Off Ver
    2013
    Posts
    3

    Re: Copypaste after conditions are met

    But it isn't solved as the above reply states.

    The data when transferred to the new sheet does not populate appropriately. If cell 11 and 61 meet the conditions, then it populates cells 11 and 61 in the new sheet as opposed to 1 and 2 which is intended. That remains the last problem. Like I have mentioned, I have tried to fill the column using ranges, but that does not work either.

    Once, I can figure out a soln for that or if someone does I'll mark it as solved.

    Thanks for the input.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. CopyPaste-HARD stuff
    By MotoXcel90 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-05-2014, 10:45 AM
  2. [SOLVED] DropBox value triggering copypaste by "SEARCHING" for the correct cells to copypaste
    By tnuis in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-03-2013, 09:41 AM
  3. Error Generation during copypaste macro run
    By ravinder_tigh in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-26-2009, 01:00 AM
  4. CopyPaste
    By Ivica Lopar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-21-2005, 08:40 PM
  5. FormatConditions appears to kill copypaste
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-18-2005, 06:05 PM

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