xldown with one row

RuinAerlin

New Member
Joined
Apr 8, 2016
Messages
10
Morning/Evening all,

What I am trying to do;
From one tab copy a list starting from c2 to last filled cell, pasting onto another tab, so the autofill after can work.

The part I am having a little difficulty with is when "C2" is the only row with data, this creates an error and stops the rest of the macro running (this is just a section of the entire macro, it is quite long and not really necessary for my question). Is there any way I can say "if further rows blank just copy C2"

Sorry just starting my foray into VBA so I know the below isn't the best coding in the world

Code:
Range("c2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("Sheet2").Select
    Range("a9").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("b9:k9").Select
    Lastrow& = Range("A:C").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Range("b9:k9").AutoFill Destination:=Range("b9:k" & Lastrow)
    On Error Resume Next
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi,

Change:
Code:
Range("c2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy


into:
Code:
Dim lr as long
lr = Cells(Rows.Count, 3).End(xlUp).Row
Range("C2:C" & lr).Copy
 
Upvote 0
I'm now getting the error at the next step, dropping formulas to any further rows if there is only one row....any ideas on how to resolve this? I thought the on error resume next would resolve this, but apparently not.
 
Upvote 0

Forum statistics

Threads
1,214,866
Messages
6,121,996
Members
449,060
Latest member
mtsheetz

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