Solved

In Excel How do I prevent an empty cell being created when I am building a list from several sources

Posted on 2014-03-24
3
211 Views
Last Modified: 2014-03-25
In Excel I have written code that works fine as long as the first Administration list, that is copied to build up a combined list (in the sheet Payroll nos), is populated.
If the first list is not populated and the second list is populated my macro 'pastes' the second list one cell down from the first cell (in Payroll nos) instead of in the first cell.
The result is that the final code to remove duplicates and put the results into a master list in column D leaves the master list empty.

As I said the code works perfectly well as long as the first list has some data
1-MODEL-v1.09.xlsm
0
Comment
Question by:DAVID131
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
nutsch earned 500 total points
ID: 39951323
First, get read of all the select statements, e.g.

Sheets("P Administration A").Select
    Range("B2:B500").Select
    Selection.Copy

Open in new window


becomes

Sheets("P Administration A").Range("B2:B500").Copy

Open in new window


That's not going to fix your macro, but it's going to make your code faster, easier to read and to maintain.

for your nextrow, after each

nextrow = Cells(Rows.Count, 1).End(xlUp).Row + 1

Open in new window


add

if nextrow=2 and len(cells(1,1))=0 then nextrow=1

Open in new window


Thomas
0
 

Author Closing Comment

by:DAVID131
ID: 39954243
Spot on Thomas works a treat
Thanks for rapid response
0
 
LVL 39

Expert Comment

by:nutsch
ID: 39954247
Glad to help.

Thomas
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question