Copy lines based on a variable

  • Thread starter Thread starter Legacy 93538
  • Start date Start date
L

Legacy 93538

Guest
Hi

Does anyone know whether its possible to get a macro to copy rows in a workbook sheet which have certain numbers in them?

For example select and copy all the rows in the worksheet which have 4 in the B Column and then paste them into the another sheet in A4.

This is what i have so far:

Code:
For X = LBound(PathArray) To UBound(PathArray)
    Set CCTLWB = Workbooks.Open(PathArray(X) & "\" & "*TrackerLog.*")
    Set CCTLWBCSht = CCTLWB.Sheets("Commentary")
    Set CCTLWBCLSht = CCTLWB.Sheets("CallLog")
 
    L = WorksheetFunction.CountA(CCTLWBCSht.Range("A:A"))
    
    CCTLWBCSht.Select
    CCTLWBCSht.Range("A" & L & ":N" & L).Copy Destination:=CCTWB.Sheets(SheetArray).Range("A1")
        
    CCTLWBCLSht.Select
    <code to copy and paste the correct line here>

Next X
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Can you describe all this in step-by-step?
 
Upvote 0
The code i pasted works like this:

  • First opens the workbook using the array being looped
  • It then sets the workbook and sheets as variables.
  • It will then select the first sheet variables
  • Then it copies data from one sheet and paste it into another workbook opened previously.
  • Then it selects the 2nd sheet variable the workbook opened
After this the code i need help with will be enter after this, i need a piece of code that will select rows in the CCTWBCLSht sheet variable which have the number 4 in the B column and paste it in to the CCTWB.sheets on cell A4
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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