Consulting

Results 1 to 3 of 3

Thread: Solved: duplicating formats

  1. #1
    VBAX Regular
    Joined
    Dec 2007
    Posts
    18
    Location

    Question Solved: duplicating formats

    This is bugging me: the following code does what it says on the tin - it duplicates the current row.

    Only thing is that a couple of the columns in the source row it duplicates are in currency format (with the symbol left aligned in the cell) and the duplicated column formats the currency within the symbol pushed left against the text.

    Is there an easy/quick way to do it? Do I have to go through every cell?

    [VBA]Private Sub BtnDuplicate_Click()
    Dim RowNum As Long
    Dim RngThisRow, RngDupRow As Range

    RowNum = ActiveCell.Row
    Range("A" & (RowNum + 1)).EntireRow.Insert
    Set RngThisRow = Range("B" & RowNum & ":R" & RowNum)
    Set RngDupRow = Range("B" & (RowNum + 1) & ":R" & (RowNum + 1))
    RngDupRow.Value = RngThisRow.Value

    End Sub
    [/VBA]

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,738
    Location
    Try this -- I had it use the first row of whatever was selected but it's easy to change.

    Paul


    [VBA]
    Sub InsertRowCopyFormats()

    If Not TypeOf Selection Is Range Then Exit Sub

    With Selection.Rows(1).EntireRow
    .Copy
    .Insert
    .EntireRow.ClearContents
    End With
    Application.CutCopyMode = False

    End Sub
    [/VBA]

  3. #3
    VBAX Regular
    Joined
    Dec 2007
    Posts
    18
    Location
    cool - took out the .EntireRow.ClearContents and it does exactly what I wanted

    (normal copy & paste only coppied the visible cells - this coppies hidden columns too )

    Thank you.
    ~G~

Posting Permissions

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