Copy / paste problem.. any ideas?

srosk

Board Regular
Joined
Sep 17, 2018
Messages
132
I have a macro that performs the following function:

Code:
Range("L2").Formula = "=VLOOKUP(C2,'152083'!B:C,2,FALSE)"Range("L2", "K" & Cells(Rows.Count, 1).End(xlUp).Row).FillDown
Range("L:L").Copy
Range("L:L").PasteSpecial xlPasteValues
Application.CutCopyMode = False

The problem, row 1 has a header, and row 2 has actual data. Sometimes, the header ends up in the value for L2. I notice this happens especially when there are only two rows on the sheet.

Any idea why / how to combat this problem? It is impacting the results of my code. Thank you
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
This line get last item from column 1:
Cells(Rows.Count, 1).End(xlUp).Row)

Change 1 by 2 , to take the last item from column B
 
Upvote 0
This line get last item from column 1:
Cells(Rows.Count, 1).End(xlUp).Row)

Change 1 by 2 , to take the last item from column B

Thanks for looking at this. For whatever reason, it doesn't work after making the change. The actual formula works perfectly fine as is, with Rows.Count, 1. The problem occurs when the copy, then paste function take place.

Any idea why that would happen?
 
Upvote 0
try this
Code:
    Range("L2").Formula = "=VLOOKUP(C2,'152083'!B:C,2,FALSE)"
    u = Range("C" & Rows.Count).End(xlUp).Row
    If u = 1 Then u = 3
    Range("L2:K" & u).FillDown
    Range("L:L").Copy
    Range("L:L").PasteSpecial xlPasteValues
    Application.CutCopyMode = False
 
Upvote 0
try this
Code:
    Range("L2").Formula = "=VLOOKUP(C2,'152083'!B:C,2,FALSE)"
    u = Range("C" & Rows.Count).End(xlUp).Row
    If u = 1 Then u = 3
    Range("L2:K" & u).FillDown
    Range("L:L").Copy
    Range("L:L").PasteSpecial xlPasteValues
    Application.CutCopyMode = False

This is SO weird. Same outcome.

Code:
Lr = WS1.Cells(Rows.Count, "A").End(xlUp).Row
Range("A2:B" & Lr).Copy
Range("A2:B" & Lr).PasteSpecial xlPasteValues

The above seems to work though (column B for this specific scenario), just thought I would share.
 
Upvote 0

Forum statistics

Threads
1,215,409
Messages
6,124,730
Members
449,185
Latest member
ekrause77

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