Copy certain columns from one spreadsheet to another, based on criteria in one column

Mldeuser

Well-known Member
Joined
Dec 27, 2008
Messages
573
Office Version
  1. 365
Platform
  1. Windows
Hello

I have a workbook with multiple spreadsheets. I would like to copy columns from Sheet A to Sheet B based on criteria found in column G on Sheet A.

Sheet A if any row in Column G has UAC then copy the information for that row found in columns B through H to, columns B through H on Sheet B.

Thank you
Mark
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Code:
Option Explicit


Sub testX()
    Dim s1 As Worksheet, s2 As Worksheet
    Set s1 = Sheets("A")
    Set s2 = Sheets("B")
    Dim i As Long, lr As Long, lrB As Long
    Application.ScreenUpdating = False
    lr = s1.Range("G" & Rows.Count).End(xlUp).Row
    For i = 1 To lr
        If s1.Range("G" & i) = "UAC" Then
            s1.Range("B" & i & ":H" & i).Copy
            lrB = s2.Range("B" & Rows.Count).End(xlUp).Row + 1
            s2.Range("B" & lrB).PasteSpecial xlPasteValues
        End If
    Next i
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    MsgBox "completed"




End Sub
 
Upvote 0

Forum statistics

Threads
1,213,549
Messages
6,114,264
Members
448,558
Latest member
aivin

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