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
 
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).
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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!
 
Upvote 0

Forum statistics

Threads
1,215,045
Messages
6,122,840
Members
449,096
Latest member
Erald

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