Copy excel sheet range from one sheet to another if not blank

I'm working as a newbie in excel VBA and can't figure this one out.
I have sheet "Main" with a range from A1 to E10000.  When I press CommandButton1 I would like the content of the range that are not blank to copy to sheet "Reconciliation" in range A1 to E10000 and then also clear values in the range of F1 to F10000.

Not sure if it matters but I have both text and number values in the range of A1 to E10000.  I have no formulas in any of the ranges.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Let's assume this was your complete range.
rangeIs this the result you want?
rmc71291Author Commented:
Oh sorry no. Just paste nonblank cells in same location on other sheet.
Martin LissOlder than dirtCommented:
So then I must assume that there's already some data in the Reconciliation sheet. True?
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Martin LissOlder than dirtCommented:
And which sheet should have range F1 to F10000 cleared?
Martin LissOlder than dirtCommented:
Here's a macro you can run. It assumes you want F1 to F10000 to be cleared on Main. If not then change line 19 from wsM to wsR.

Sub DoReconciliation()

Dim lngRow As Long
Dim lngCol As Long
Dim wsM As Worksheet
Dim wsR As Worksheet

Set wsM = Sheets("Main")
Set wsR = Sheets("Reconciliation")

For lngRow = 1 To 10000
    For lngCol = 1 To 5
        If wsM.Cells(lngRow, lngCol) <> "" Then
            wsR.Cells(lngRow, lngCol) = wsM.Cells(lngRow, lngCol)
        End If

End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rob HensonFinance AnalystCommented:
I believe you can just Copy the whole range but when pasting use the paste Special option and choose the Skip Blanks option. This means that if a blank cell has been copied, it will be ignored when pasting and as such will not overwrite existing values in the destination sheet with a blank cell.

Rob H
rmc71291Author Commented:
This was exactly what I needed!  I did change from wsM to wsR.  Most sincere thanks!
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2015
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.