Limit columns copied to another sheet and combine modules

smr108

New Member
Joined
Dec 27, 2020
Messages
6
Office Version
  1. 365
Platform
  1. Windows
I have looked on the internet to learn how to write something to copy data from one sheet to another based on values in a column. I have created 3 modules to do that. One of them is below. Each time it overwrites everything in the destination sheet. Is there a way to limit the columns that get copied into the destination sheet? I also run each module as a macro but would like to combine all of them and run them at the same time. Is that possible?

VBA Code:
Sub CopyEarn()
    Dim c As Range
    Dim j As Integer
    Dim Source As Worksheet
    Dim Target As Worksheet

    ' Change worksheet designations as needed
    Set Source = ActiveWorkbook.Worksheets("Transactions")
    Set Target = ActiveWorkbook.Worksheets("Earn")

    j = 1     ' Start copying to row 1 in target sheet
    For Each c In Source.Range("B2:B1000")   ' Do 1000 rows
        If c = "Coinbase Earn" Then
           Source.Rows(c.Row).copy Target.Rows(j)
           j = j + 1
        End If
    Next c
End Sub
 

rollis13

Active Member
Joined
Jul 30, 2012
Messages
371
Office Version
  1. 2016
Platform
  1. Windows
Since I can't access your file and I haven't a Crystall Ball, if with the other sheets the macro works, if you have a problem this could only mean that the spelling of "Buy" in the array in the macro o in the sheets tab are different, maybe uppercase or trailing spaces or in the data (column B).
 

Some videos you may like

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

smr108

New Member
Joined
Dec 27, 2020
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Bingo. It was something to do with spelling or format or something with Buy. I just renamed Buy in the code and renamed the sheet. I have no idea why as I didn't change anything between updates. Thanks again!
 

Watch MrExcel Video

Forum statistics

Threads
1,123,281
Messages
5,600,720
Members
414,401
Latest member
grenona2020

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
Top