Consulting

Page 1 of 3 1 2 3 LastLast
Results 1 to 20 of 46

Thread: How to copy past only the cell marked in red

  1. #1

    How to copy past only the cell marked in red

    pasi.jpg

    Hi I am trying to copy /paste only the cells with red color font into new sheet how do I do this? I don't want the cell in black.
    Thanks,
    Pasi

    here is my code forgot to put in:

    F
    or i = 1 To Range("A65536").End(xlUp).Row
    '        ' If Application.WorksheetFunction.CountIf(Range("D:D"), Range("A" & i)) = 1 Then
    '
    '                ' ColorIndex = 3 Then
             With Range("A" & i).Font
                  ' With Range("A:A").ColorIndex
                   ' .Bold = True
                    '.ColorIndex = 3
                    Range("A" & i).Select
                    Selection.Copy
               Sheets.Add After:=Sheets(Sheets.Count)
              ActiveSheet.Paste
    End With
        'End If
        End If
        Next I
    Last edited by Aussiebear; 01-23-2014 at 04:46 PM. Reason: enclosed code with tags

  2. #2
    Presuming that your data is only in columns A & B.

    Sub FontColor()
    
    LastRow = Range("A9999").End(xlUp).Row
    
    
    'ColourIndex "3" = Red
    
    
    For x = 1 To LastRow
    
    'Check if the cell contains the font colour RED (3)
    If Range("A" & x).Font.ColorIndex = 3 Then
    
    'If it does, then copy the data
        Range("A" & x, "B" & x).Copy
    
    'Check to see if A1 is blank on sheet2
            If Sheets("Sheet2").Range("A1").Value = "" Then
    
    'If it is, then paste the data there
                Sheets("Sheet2").Range("A1").PasteSpecial xlPasteAll
                Else
    
    'If it is already taken, then paste the data into the next row below
                Sheets("Sheet2").Range("A9999").End(xlUp).Offset(1, 0).PasteSpecial xlPasteAll
            End If
    End If
    Next x
    
    
    End Sub
    I hope this helps

  3. #3
    Thank you Ashelyuk! I am getting error on the line If Sheets("Sheet2").Range("A1").Value = "" Then it wont go further? not sure why?

  4. #4
    Do you have another sheet (a tab at the bottom) called Sheet2 ??



    If you don't, then this is probably why your getting that error.

  5. #5
    NO I don't is there any way just to say copy/paste only reds into another sheet without mentioning sheet number?
    Also the code only copy pastes the first row not the rest? I only get one row copied?
    Thanks so much!!!

  6. #6
    It will only copy the first row, because you are getting an error. So therefore the rest of the code can't execute.

    Use: Sheets(2) instead of Sheets("Sheet2"), this will paste to your second sheet, no matter what it's called..

    I have modified my code:

    Sub FontColor()
    
    LastRow = Range("A9999").End(xlUp).Row
    
    
    'ColourIndex "3" = Red
    
    
    For x = 1 To LastRow
    
    'Check if the cell contains the font colour RED (3)
    If Range("A" & x).Font.ColorIndex = 3 Then
    
    'If it does, then copy the data
        Range("A" & x, "B" & x).Copy
    
    'Check to see if A1 is blank on sheet2
            If Sheets(2).Range("A1").Value = "" Then
    
    'If it is, then paste the data there
                Sheets(2).Range("A1").PasteSpecial xlPasteAll
                Else
    
    'If it is already taken, then paste the data into the next row below
                Sheets(2).Range("A9999").End(xlUp).Offset(1, 0).PasteSpecial xlPasteAll
            End If
    End If
    Next x
    
    
    End Sub

  7. #7
    This is how I have it now and its working fine with your added few lines but only copies the first row not all the red one?
    Sub ColorDuplicates()
    'Color duplicate items between columns A and D
        For i = 1 To Range("D65536").End(xlUp).Row
             If Application.WorksheetFunction.CountIf(Range("A:A"), Range("D" & i)) = 1 Then
                With Range("D" & i).Font
                .ColorIndex = 5
                    .Bold = True
                With Range("E" & i).Font
                    .ColorIndex = 5
                    .Bold = True
                End With
                End With
             End If
        Next i
       For i = 1 To Range("A65536").End(xlUp).Row
             If Application.WorksheetFunction.CountIf(Range("D:D"), Range("A" & i)) = 1 Then
                With Range("A" & i).Font
                .ColorIndex = 3
                    .Bold = True
                                
                With Range("B" & i).Font
                    .ColorIndex = 3
                    .Bold = True
                 End With
                End With
                
                 If Range("A" & i).Font.ColorIndex = 3 Then
                           
                Range("A" & i, "B" & i).Copy
               
                 Sheets.Add After:=Sheets(Sheets.Count)
                 ActiveSheet.Range("A65536").End(xlUp).Offset(0, 0).PasteSpecial xlPasteAll
        ActiveSheet.Paste
       
       End If
                         
                End If
                  
           
       
       
        Next i
    Last edited by Aussiebear; 01-23-2014 at 04:47 PM. Reason: enclosed code with tags

  8. #8
    Sorry still getting If Sheets(2).Range("A1").Value = "" Then error? with you new code?

  9. #9
    Or you could try this.
    Sub Try_This()
        Dim c As Range
        For Each c In Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)
            If c.Font.ColorIndex = 3 Then c.Resize(, 2).Copy Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Offset(1)
        Next c
    End Sub
    If you have a large range, autofilter will be faster

  10. #10
    Getting error on this section: c.Resize(, 2).Copy Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Offset(1)

  11. #11
    Not really sure why your getting errors on that line.
    Unless there is something specific on your workbook preventing it.

    Are you able to upload a copy of your workbook so we can analyse it.

  12. #12
    What does the error say?
    Do you have a Sheet called "Sheet2"? Previously you mentioned that you didn't
    Change the Sheets("Sheet2") to Sheets("Sheetname where you want it copied into")

  13. #13
    How do I upload this file? Can you set it just to copy all the reds cells from current sheet to another sheet without mentioning the sheet(2)? like what I had: " Sheets.Add After:=Sheets(Sheets.Count)" ?
    Thanks!

  14. #14
    Its says script out of range and highlite in yellow " c.Resize(, 2).Copy Sheets(2).Cells(Rows.Count, 1).End(xlUp).Offset(1)" ? Can you just say next sheet .add? like ---> Sheets.Add After:=Sheets(Sheets.Count)'
    Thanks!

  15. #15
    Theres an attachment button when you choose to reply via the advanced form.




  16. #16
    AhleyUk file is attached.
    tanks.
    Attached Files Attached Files

  17. #17
    Hi,
    I'm not really sure why your getting the errors ??

    I just ran my code on your uploaded workbook, and this is the results that I got.



    I believe this is what you want - more or less.
    As for the errors that you seem to be getting?? I don't know? My code seems to work perfectly fine on my end.

  18. #18
    HI ,

    That is strange! not sure whats going on?? hmmm???

    Thank you!!!!

  19. #19
    Ok I think I know what it is! When I open my xls sheet it only has 1 sheet with data in it your codes is looking for sheet 2 which is not there. I think that's why! Any way to modify the code not to look for sheet number ? just say : Sheets.Add After:=Sheets(Sheets.Count)
    ActiveSheet.Paste

    That would be great!
    Thanks so much!

  20. #20
    Try the attached
    Attached Files Attached Files

Posting Permissions

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