PDA

View Full Version : Solved: duplicating formats



Gadget
01-25-2008, 04:10 AM
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?

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

Paul_Hossler
01-25-2008, 02:56 PM
Try this -- I had it use the first row of whatever was selected but it's easy to change.

Paul



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

Gadget
01-28-2008, 03:44 AM
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 :D)

Thank you.
~G~