1

I have an Excel format that looks like this:

enter image description here

What I need is a VBA code in Excel that will read all the data in column A and look for any text in italic format then check if it has a duplicate data on the same column. If yes, that data will be written on column B.

This is what I have so far:

 Sub FillDuplicates()
    Dim lastrow As Long
    lastrow = Cells(Rows.Count, "A").End(xlUp).Row 'find last row in column A

    For x = 1 To lastrow
        If Cells(x, 2).Value <> "" Then 'Check if cell in column B is empty
            For y = 1 To lastrow
                If Cells(y, 1).Value = Cells(x, 1).Value Then 'Compares cell against each value in column A
                    Cells(y, 2).Value = Cells(x, 2).Value 'If matches, add value in column B
                End If
            Next y
        End If
    Next x
 End Sub
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • 1
    Need to tell you that StackOverflow is not a free code writing service. What did you try so far? Can you show us your code? – Pᴇʜ Mar 20 '17 at 10:01
  • Hi, @Peh. This is what I have so far: Sub FillDuplicates() Dim lastrow As Long lastrow = Cells(Rows.Count, "A").End(xlUp).Row 'find last row in column A For x = 1 To lastrow If Cells(x, 2).Value <> "" Then 'Check if cell in column B is empty For y = 1 To lastrow If Cells(y, 1).Value = Cells(x, 1).Value Then 'Compares cell against each value in column A Cells(y, 2).Value = Cells(x, 2).Value 'If matches, add value in column B End If Next y End If Next x End Sub – user3445540 Mar 20 '17 at 10:06
  • 1
    I just want to know if there's a way to identify whether text is in italic? – user3445540 Mar 20 '17 at 10:08
  • Next time please don't use comments for adding code. You can edit the question to add things like code or images. – Pᴇʜ Mar 20 '17 at 10:16
  • Alright. Sorry for the inconvenience. – user3445540 Mar 20 '17 at 10:19
  • By Googling "vba font italic" you get 115,000 results, the first of which is the [MSDN documentation](https://msdn.microsoft.com/en-us/library/office/ff836794.aspx), giving the example `Range("A1:A5").Font.Italic` which returns a Boolean... it took you longer to write the question than it would have taken to search for the answer! – Wolfie Mar 20 '17 at 10:38

1 Answers1

1

Try

If Cells(x, 2).Value <> "" and Cells(x, 2).Font.Italic = true then
Pspl
  • 1,398
  • 12
  • 23