VBA if column B contains "New" copy only specific cells to another sheet

cizzett

Board Regular
Joined
Jan 10, 2019
Messages
121
So I have a heavily VBA and Macro laden workbook that I have continued to work on to simplify and streamline data tasks, as well as keeping the others from struggling in my absence.

What I am trying to do is if column B contains text "New" then copy ONLY cells D:F, I, O:P and paste them to the next available row on worksheet L.W.S.

I have one VBA code that works to copy the entire row of data and paste it to another workbook (My annual summary of data) but I am struggling to make it work for just these specific cells into the worksheet in this same workbook.

Any Ideas?

The data is on on worksheet "Today" and the worksheet I want to paste to is L.W.S.

Thanks in Advance
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hello Cizzett,

Try the following code:-
Code:
Sub Test()

Dim ws As Worksheet: Set ws = Sheets("Today")
Dim sh As Worksheet: Set sh = Sheets("L.W.S.")

Application.ScreenUpdating = False

With ws.[A1].CurrentRegion
        .AutoFilter 2, "New"
        Union(.Columns("D:F"), .Columns("I"), .Columns("O:P")).Offset(1).Copy sh.Range("A" & Rows.Count).End(3)(2)
        .AutoFilter
End With

Application.ScreenUpdating = True

End Sub

It assumes that data starts in Row2 with headings in Row1.

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0
Hey Thanks, this works well. Is it possible to alter this to paste text only? I dont want to drag formatting etc along.
 
Upvote 0
I've been playing with this but I need to figure out how to get it to only copy those specific cells

Code:
Sub LotWS()


Application.DisplayAlerts = False
        Application.ScreenUpdating = False
        
   Dim Nws As Worksheet
   Dim Mws As Worksheet
    Set Mws = ThisWorkbook.Sheets("Today")
        Set Nws = ThisWorkbook.Sheets("L.W.S.")
        
    If Mws.FilterMode Then Mws.ShowAllData
            Mws.Range("A1:j1").AutoFilter 2, "New"
        Mws.UsedRange.Offset(1).SpecialCells(xlVisible).Copy
    Nws.Range("A2").End(xlUp).Offset(1).PasteSpecial xlPasteValues
   Mws.ShowAllData
   
  
          Application.ScreenUpdating = True
    Application.DisplayAlerts = True


End Sub
 
Last edited:
Upvote 0
Hello Cizzett,

To paste values only:_


Code:
Sub Test()

Dim ws As Worksheet: Set ws = Sheets("Today")
Dim sh As Worksheet: Set sh = Sheets("L.W.S.")

Application.ScreenUpdating = False

With ws.[A1].CurrentRegion
        .AutoFilter 2, "New"
        Union(.Columns("D:F"), .Columns("I"), .Columns("O:P")).Offset(1).Copy
     [COLOR=#ff0000]   sh.Range("A" & Rows.Count).End(3)(2).PasteSpecial xlValues[/COLOR]
        .AutoFilter
End With

Application.ScreenUpdating = True

End Sub

Cheerio,
vcoolio.
 
Upvote 0
You're welcome Cizzett. I'm glad that I was able to help.

Cheerio,
vcoolio
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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