VBA - Copy cells from one tab to another and paste in first empty cell in column

Final Frontier

New Member
Joined
Sep 16, 2014
Messages
17
Hello,

I am making an attempt at using VBA for the first time and it is not going well. I tried searching for help but I was getting confused when I try to modify to my own data.

My goal is to copy data from the Customer Data tab and paste into the Revenue tab. I will need to copy a few columns on the Customer Data tab until the first blank cell and then paste values into the Revenue tab. I will also need Column C on the revenue tab to label using the customer name (example: if customer A is 50 rows, I want to list the customer name in the Column C cells for only those 50 rows). Then I need to repeat this using different cells in different columns on the Customer Data tab. In short, I am looking to copy customer data and stack in the Revenue tab.

The code for the first 2 customers is below. Most was created using the Record Macro function as an example for what I am trying to accomplish. Can someone help me with this or direct me to a good source?

Thank you!

Code:
'Clear Contents
 
With Sheets("Revenue")
.Rows(4 & ":" & .Rows.Count).Delete
End With
 
'Copy Customer A data from Customer Data tab to Revenue tab
 
    Sheets("Revenue").Select
    Range("F3").Select
    Sheets("Customer Data").Select
    Range("B9").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("Revenue").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("G3").Select
    Sheets("Customer Data").Select
    Range("H9").Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Revenue").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("I3").Select
    Sheets("Customer Data").Select
    Range("E9").Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Revenue").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("E3").Select
    Application.CutCopyMode = False
 
'Paste "Customer A"
 
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
 
With Sheets("Revenue")
  For i = 3 To lastRow
    If Len(Trim(.Range("F3" & i).Value)) <> 0 Then _
    .Range("E3" & i).Formula = "=Customer A"
  Next i...
 
‘Copy Customer B data from Customer Data tab to Revenue tab
 
    Range("E280").Select
    Sheets("Customer Data").Select
    Range("J7").Select
    Sheets("Revenue").Select
    Range("D4:D279").Select
    Selection.ClearContents
    Range("D3").Select
    Selection.AutoFill Destination:=Range("D3:D279")
    Range("D3:D279").Select
    Range("E280").Select
    Sheets("Customer Data").Select
    Range("J7").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("Revenue").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
'Paste "Customer B"
 
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
 
With Sheets("Revenue")
  For i = 3 To lastRow
    If Len(Trim(.Range("F3" & i).Value)) <> 0 Then _
    .Range("E3" & i).Formula = "=Customer B”
  Next i...
 

Excel Facts

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

Forum statistics

Threads
1,214,789
Messages
6,121,605
Members
449,038
Latest member
Arbind kumar

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