Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy a rows contents and formatting (to another sheet)

What do I want is to copy an entire row's contents and formatting to another sheet.

At the moment I've had to settle for setting the old cells contents to the new cells contents and in doing so it only copies the contents and not the formatting. (my cells have different colours that need to be carried across)

At the moment I have the following: (this works fine for cells in the same sheet)

Range(Cells(45, 2), Cells(45, 3)).Copy Range(Cells(50, 2), Cells(50, 3))

However, I'm trying to do it from one sheet to another. (Copy from sheet 'Front_Page' to 'vg'). I tried using the following, obviously it doesn't work, but can someone please tell me what am I doing wrong?

Range.Worksheet("Front_Page").Range(Cells(45, 2), Cells(45, 3)).Copy Worksheet("vg").Range(Cells(50, 2), Cells(50, 3))
like image 734
user1148630 Avatar asked Feb 05 '12 22:02

user1148630


People also ask

How do I automatically move a row to another sheet in Excel based on cell value?

In the opening Select Specific Cells dialog box, choose Entire row in the Selection type section, select Equals in the Specific type drop-down list, enter the cell value into the text box and then click the OK button.

How do you copy a row if it contains certain text to another worksheet?

Use the shortcut CTRL A to select all the data. Use the shortcut CTRL C to copy the data (this will copy visible records only) Navigate to the worksheet that you want to copy the records to. Click in the cell that you want to paste your records into.


1 Answers

Looks like you try to copy cells from "Front_Pages" to "vg" since you use "cells" inside "range"

Range (cells ...).

If so, you can simply change the cell format as excel general range; try this code :

Sheets("vg").Range("B5") = Sheets("Front_Pages").Range("B4")
Sheets("vg").Range("C5") = Sheets("Front_Pages").Range("C4")
like image 124
Aji Avatar answered Oct 25 '22 04:10

Aji