Moving data automatically
-
QUESTION: Single workbook, five spreadsheets (sheet1=prospect, sheet2=new sale, sheet3=upgrade, sheet4=won, sheet5=lost) I want to enter data in sheet one (rows) then use a dropdown list (column M) to automatically move the data to the next sheet (i.e. new or upgrade) and delete the data from sheet1. Then from new/upgrade sheets i want to move the data to Won/Lost sheets by way of another dropdown list I have the workbook made, but can't get the data transfer to work. ANSWER: Jay, there are three different type of dropdowns - all programmed differently. Since you don't say, I will assume you are using the list option of data validation so that a selection from the list will trigger the change event in the sheet. Further assume that the dropdown contains the names of the sheets. (copying the row will copy the dropdown so it can be used again to make progressive selections). I will assume you are familiar with events and know how to program with vba at least fairly well - if not, post back a followup if you need further explanation or have additional questions. You could use the workbook level SheetChange event which you must place in the Thisworkbook module. In the thisworkbook module, at the top of the module, in the left dropdown select Workbook and in the right dropdown select SheetChange. That should put in the SheetChange event declaration in the module: Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range) End Sub the Sh argument will have a reference to the sheet where the event was triggered and the Target argument will have a reference to the cell that triggered the event. So you would add code such as this: Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range) Dim sh1 As Worksheet, r As Range If LCase(Sh.Name) = "prospect" Or LCase(Sh.Name) = "new sale" Or _ LCase(Sh.Name) = "upgrade" Then ' check if it is one of the appropriate sheets If Target.Column = 13 Then ' check if column M If Target.Count = 1 Then ' check if only one cell triggered On Error Resume Next Set sh1 = ThisWorkbook.Worksheets(Target.Text) On Error GoTo 0 If Not sh1 Is Nothing Then ' check if the sheet name is valid Set r = sh1.Cells(Rows.Count, 1).End(xlUp)(2) ' find the next available row Application.EnableEvents = False ' turn off events Target.EntireRow.Copy r ' copy the row Target.EntireRow.ClearContents ' clear the row Application.EnableEvents = True ' turn on events End If End If End If End If End Sub That was tested and worked for me as expected - but I have made a lot of assumptions and don't know what your data looks like. ---------- FOLLOW-UP ---------- QUESTION: First, thank you for timely response. I know what VBA is, how to get in, basic understanding. Nothing more. But I use to program 15+ years ago. Assumption on dropdown is correct, list-type, but no it does not match sheet names - this would be easy to fix. I will test and reply back if I run into questions/problems. Does this also handle the last step - to move data from New/Upgrade to Won/Lost with same type of dropdown lists? ANSWER: Jay, In my dropdown I had all sheet names except Prospect. So conceivably, any of the 4 other sheets could be selected and the code would execute it. The macro copies the entire row and pastes it into the next available row on the specified sheet. Since it is copying the entire row, the dropdown from the prospect sheet would be reproduced in the destination sheet. So when a sheet selection is made from New or Upgrade, the row is copied again. Of course, the code could be altered to copy less than a whole row (so the dropdown is not copied) and it could be modified to put in a dropdown in the destination to only have pertinent choices for the sheet where the data is copied (or modify the list). The code could be modified to accomodate whatever choices are offered and equate that choice to a specific sheet. When you go into the VBE (alt+F11), on the right you should see the project explorer. Your project/workbook should be listed there. Click on the thisworkbook entry for your project (expand it in the tree control if it has no children elements). You can right click on Thisworkbook under your project and select view code. Chip Pearson has an overview of events at http://www.cpearson.com/excel/events.aspx ---------- FOLLOW-UP ---------- QUESTION: Good morning. Cut & pasted code into the ThisWorkbook. Saved, closed, reopened, enabled macros and no joy. With test data in Prospect sheet I tried all pulldown choices and nothing. No data copy.
-
Answer:
Jay, code was tested and worked fine for me. Sure you have macros enabled? if you want to send me the workbook I can take a look. Since it works fine for me, there isn't a lot I can tell you without looking at your implementation. You could have spaces in your sheet names and they don't actually match what is in the dropdown. Send to: Include what version ofyou have.
Miningco.com Visit the source
Related Q & A:
- How would you transfer data between your data structures and databases?Best solution by Programmers
- How to store data in php and get data from php?Best solution by Stack Overflow
- What are some good "beginner level" data modeling/analytics approaches to kick start a data science/analytics team?Best solution by Quora
- What are some phones for Verizon Wireless without a data plan or with a cheap data plan?Best solution by Yahoo! Answers
- What's the difference between a static data member and a regular data member?Best solution by eHow old
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.