Nullbyte
Nullbyte

Reputation: 251

Copy range from one sheet and insert into another

I simply need to copy from A1 to Q9 from sheet "Header" and insert such range into sheet "Master_Sheet" inthe same range. I say insert because at the time the above macro is called, the range has data in it and I do not have to cancel the content. I tried something along these lines that I have copied but it would copy the data on top of the existing once and I need instead to insert them with formatting. Obviopusly I do not know VBA.

Sub Main()
    Sheets("Master_Sheet").Range("A1:Q9").Value = Sheets("Header").Range("A1:Q9").Value
End Sub

Your help will be really appreciated.

Upvotes: 0

Views: 3316

Answers (1)

Sathish Kothandam
Sathish Kothandam

Reputation: 1520

Your code copies the values alone not formatting. if you want copy the data with formatting try the below code it should work

     Sub Main()
        Dim lrow As Integer

        With Sheets("Header")
        lrow = Sheets("Master_Sheet").Range("A1").CurrentRegion.Rows.Count
        .Range("A1:Q9").Copy Sheets("Master_Sheet").Range("A" & lrow + 1) ' - for cut
        End With

    End Sub

or if you to insert the at the begging of the cell (A1 - in master sheet)

Use below code

Sub Macro3()
    Sheets("Header").Range("A1:Q9").Copy
    Sheets("Master_Sheet").Select
    Range("A1").Select
    Selection.Insert Shift:=xlDown
    Application.CutCopyMode = False
End Sub

The above code copies the data from A1:Q9 from header sheet and paste at the end of master sheet A column

Upvotes: 2

Related Questions