AllExperts > Excel 
Search      
Excel
Volunteer
Answers to thousands of questions
 Home · More Excel Questions · Answer Library  · Encyclopedia ·
More Excel Answers
Question Library

Ask a question about Excel
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Bill
Expertise
I can provide help with most all EXCEL questions and most all questions about writing EXCEL macros. I have been developing macros for about 10 years in EXCEL and have switched to it from Lotus 1-2-3 after about 10 years of writing macros in it. Typically, I will not write a macro for you unless it is very short because of all the details a macro has to know about to work every time all the time. Please understand that I do not know it all and will be the first to say so. As politely as possible, I don't write macros for people on this site who need one, want one, seem to imply that they need one, and/or seem to think I am expected to write one UNLESS they are very short, quick, and simple. 99% of all macros are more involved than what you think and rarely am I provided with enough specific and complete details to have the code work the first time and every time. This typically means too many follow-up emails, and subsequent macro changes due to lack of specific details, just to get those details so that the macro would work, all of which is on my own free time. The voice of experience from responding to many questions from people who ask me to write a macro for them from this site tells me this. I don't mean to come across as unhelpful but macros are usually very specific and without ALL of the specifics the macro I would write will not address all of your needs and the layout, location, formatting, conditions, etc. of your data and any related files the macro would have to work with. What seems like a simple task to you is almost always more involved than what you think to have the macro ALWAYS work in EVERY situation. If you have a macro you have already written and have a question about it then perhaps I could help with that. I am sure and hope you can and do understand.

 
   

You are here:  Experts > Computing/Technology > Microsoft Software > Excel > Macro data validation before copy

Excel - Macro data validation before copy


Expert: Bill - 7/10/2009

Question
Hello Bill,
I want to say thank you in advance for your willingness to share your time and knowledge.  I have written a macro that will copy data from a working sheet to another sheet within the same workbook for historical purposes.  The only thing that I cannot figure out is how to verify that all of the cells I am copying have data in them.  An empty cell would mean that the copy process occurred before all necessary data was entered.  I have already created data validation scenario's for the necessary cells.  Can you tell me how to verify/validate that each cell being copied has some type of data when the macro is run before it copies and clears the contents?  Here is the current macro I am using.  
   Range("A5:L5").Select
   Selection.Copy
   Sheets("Saved").Select
   Selection.Insert Shift:=xlDown
   Sheets("Current").Select
   Range("B5:K5").Select
   Application.CutCopyMode = False
   Selection.ClearContents
End Sub
Thanks again,
Jimmy


Answer
You have to loop thru each cell FIRST, something like:

Dim Data_Complete as Boolean
For X = 1 to 12
  'checks to see if the cell has data
  If Range("A5").Offset(X-1,0) = "" Then
     Data_Complete = False
  End if
Next X

If Data_Complete = True Then
  'run your code
Else
  Msgbox "Data is incomplete, data should not be copied"
End If

Add to this Answer   Ask a Question


 
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.