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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
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,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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