Copy specific columns vba

owen4512

Board Regular
Joined
Dec 10, 2014
Messages
71
Hi all,

The below code works however it requires some adapting to meet my needs. Currently the below will copy data on sheet3 in range A:N and paste this to sheet5 range B9. The difficulty i'm having is that i don't want to copy all the data from A:N but instead i want to copy data in B,C,E,H,I and paste into sheet5 B9

How can i adapt the below? Any help would be appreciated :)

VBA Code:
Sub Create_Report()

    Dim i, last_row_Data As Integer
    Dim Records As Long

    Records = Sheet1.Range("N15").Value
    last_row_Data = Application.WorksheetFunction.CountA(Sheet2.Range("A:A")) + 1 'Finds last row on 'All-Data' tab
    
    For i = 2 To last_row_Data
        If Sheet2.Range("M" & i).Value = "Outstanding" Then
            Records = Records + 1
            Sheet2.Activate
            Sheet2.Range(Cells(i, 1), Cells(i, 14)).Copy
            Sheet5.Activate
            Sheet5.Range("B9").PasteSpecial xlPasteValuesAndNumberFormats
        End If
     Next i
    
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Here is one way.

Replace this line:
VBA Code:
           Sheet2.Range(Cells(i, 1), Cells(i, 14)).Copy
with this:
VBA Code:
           rng = "B" & i & ", C" & i & ", E" & i & ", H" & i & ", I" & i
           Sheet2.Range(rng).Copy
 
Upvote 0
Solution
Here is one way.

Replace this line:
VBA Code:
           Sheet2.Range(Cells(i, 1), Cells(i, 14)).Copy
with this:
VBA Code:
           rng = "B" & i & ", C" & i & ", E" & i & ", H" & i & ", I" & i
           Sheet2.Range(rng).Copy
Thank you, Joe - That's done the trick!
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,957
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top