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
212 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 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