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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

708 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now