Forum Discussion

infinity94's avatar
infinity94
Copper Contributor
Jun 01, 2021
Solved

VBA copying specific columns in new sheet

Hi all,

I need some help. I am trying to create an easy code on how to copy a specific column from one sheet to the other if a condition is meet. If column F ="Yes" in sheet "request then I want column B, E,G copied into the next Sheet "Sheet1". I don't want to specify how many rows will I have because it can change.

Can someone help me with this?

That's what i tried but not copying all columns so far.

link for my spreadsheet:https://onedrive.live.com/edit.aspx?action=editnew&resid=C051D6F258D8A704!124&ithint=file%2cxlsx&action=editnew&wdNewAndOpenCt=1622564472009&wdPreviousSession=b973bfc4-b1b5-41be-a7e7-b0b5fd6e15cc&wdOrigin=OFFICECOM-WEB.START.NEW

 

my code:

Private Sub CommandButton1_Click()

a=worksheets("Request").Cells(Rows.Count,1)End(xlUp).Row

For i=2 To a

Worksheets("Request"). Activate

If Worksheets("Request").Cells(i,6).Value="Yes" Then

Range(Cells(i,1), Cells(i,6)).Select

Selection.Copy

Worksheets("Sheet1").Activate

b=Worksheets("Sheets1").Cells(Rows.Count,1).End(xlUp).Row

Worksheets(Sheets1").Select

ActivateSheet.Paste

End If

Next

Application.CutCopyMode=False

End Sub

 

5 Replies

Resources