Help! Need help to correct and undetermined Range to avoid #N/A's

liferg

Board Regular
Joined
May 21, 2013
Messages
88
I had recorded a macro and the given range was ("P2:P3247"), however this number can vary from day to day, higher or lower. If the number is lower then it fills in the #N/A's, and if it goes over then I lose data for the remainder of the macro. I have extended it out to 5000 just to make sure I get all of the data if it goes over, but then I'm stuck with a lot more of the #N/A's. I attempted to use a code from a google search and now I can't get it back to the way it was. Can someone please provide me with some assistance on this? I have a report that needs to be done by 2:00.

Code:
 LastRow = Cells(Cells.Rows.Count, "P").End(xlUp).Row
    Range ("P1:P" & LastRow)
    With Range("P2")
        .AutoFill Destination:=Range("P2:P" & InLastRow)
    End With
    With Range("P2:P5000")
        .Copy
        .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
    End With
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi,

I think the problem will be in this line:-

LastRow = Cells(Cells.Rows.Count, "P").End(xlUp).Row

You need to check for last row to fill to in a column different from the one you are filling.

Which column determines
"however this number can vary from day to day"
& replace "P" with that column.

Hope this helps,

Eric.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,084
Messages
6,128,722
Members
449,465
Latest member
TAKLAM

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