Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Apr 2003
    Location
    Kontich, Vlaanderen, Belgium
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macro to copy only bold lines (2002 (SP3))

    Hi all,

    I am stuck with the following: Every month I need to analyze a lot of data to make a report out of it. The data is provided through several (similar) xls-files. As the data is confidential, I have created a demo file to illustrate what I mean.

    In the demo file you see that there are lines in bold and others not. I need to copy the bold lines only to a place under the actual range of data lines (I hope I make myself clear here). The size (meaning the number of data lines) of the range can differ in each xls-file and also each month. I did this by hand in the demo file. Surely this can be done with a macro, but my knowledge of VBA is insufficient to tackle this one.

    MTIA,

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to copy only bold lines (2002 (SP3))

    Try this macro:

    Sub CopyBoldRows()
    Dim lngSourceRow As Long, lngTargetRow As Long
    Application.ScreenUpdating = False

    lngTargetRow = Range("A65536").End(xlUp).Row
    For lngSourceRow = 2 To Range("A1").End(xlDown).Row
    If Cells(lngSourceRow, 1).Font.Bold = True Then
    lngTargetRow = lngTargetRow + 1
    Rows(lngSourceRow).Copy Destination:=Rows(lngTargetRow)
    End If
    Next lngSourceRow

    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    End Sub

  3. #3
    2 Star Lounger
    Join Date
    Apr 2003
    Location
    Kontich, Vlaanderen, Belgium
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to copy only bold lines (2002 (SP3))

    You did it again, Hans !

    Your code just works fine. I only changed your code to also include the "header" row and to leave a blank line between the original data range and the copied selection (just to have those copied rows apart from the source).

    Thanks again !

Posting Permissions

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