MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Feb 28th, 2002, 07:36 PM   #1
Skebo
New Member
 
Join Date: Feb 2002
Posts: 20
Default

I'm trying to create paste links between a number of cells on various sheets.

On sheet1 I have two columns that contain validation lists. The values in the columnA (first list) correspond to worksheet names. The values in columnB (second list) corresponds to values found in column D on the other sheets.

I want the user to select a value from each list and also to input data into column C on sheet1.
Based upon the two values I would think you could select the proper sheet and row and then paste the value from column C into that specific row on that specific sheet.

Something like:
Sheets(ActiveCell.Value).Select ???

I don't know where to begin on the row selection.
Any guidance would be greatly appreciated.
Skebo is offline   Reply With Quote
Old Feb 28th, 2002, 11:33 PM   #2
Guest
 
Posts: n/a
Default

I'd like to know how to do something very similar to this.
  Reply With Quote
Old Mar 1st, 2002, 02:41 AM   #3
Derek
Board Regular
 
Join Date: Feb 2002
Location: Perth Australia
Posts: 1,567
Default

Hi there

Try this, it might give you some ideas:
Sheet 1 Column A = validation list showing sheet names ( type names in list like Sheet2 )
Sheet 1 Column B = validation list showing values which correspond to identical values in D:D of other sheets
Sheet 1 Column C is for data to be transferred to appropriate sheet (pastes in cell to right of value selected)
Sheet1 Put this formula in D1 and scroll down
="E"&MATCH(B1,INDIRECT((A1)&"!D:D"),0)
(E is the column your data will paste into)

Right click Sheet1 tab, left click View Code then paste in the following code

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 3 Then
Application.ScreenUpdating = False
Range(Target, Target.Offset(0, 1)).Copy
Sheets(Target.Offset(0, -2).Value).Select
ActiveSheet.Range("A1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
ActiveSheet.Range("A1").Copy
ActiveSheet.Range(ActiveSheet.Range("B1").Value).Select
ActiveSheet.Paste
ActiveSheet.Range("A1:B1").ClearContents
Sheets("Sheet1").Select
Application.CutCopyMode = False
End If
End Sub

It will activate after a data entry is made in a cell in Sheet1 Column C
Be aware that it first pastes values to cells A1:B1 on the sheet in question. A1 gets your data and B1 gets the address to put it on that sheet. It then copies A1 and pastes it into the address shown in B1. It then clears A1:B1

Hope this helps a bit
Good Luck
Derek
Derek is offline   Reply With Quote
Old Mar 1st, 2002, 12:13 PM   #4
Skebo
New Member
 
Join Date: Feb 2002
Posts: 20
Default

Derek,
You're an All-Star. Thanks.

I have one other issue, but I haven't really done my homework on it yet. I might be able to find an answer elsewhere on the site, but any input you have would be great!

D may contain multiple rows with the same value. In cases where we have already filled in E, I would like it to look for the next matching D with an unfilled E.
Skebo is offline   Reply With Quote
Old Mar 2nd, 2002, 04:49 AM   #5
Derek
Board Regular
 
Join Date: Feb 2002
Location: Perth Australia
Posts: 1,567
Default

Hi again Skebo

Here is the simplest solution I could devise to your question but it involves using a hidden column on each of your other sheets. Here's what you do:

1. Insert a column to left of D:D in all other sheets (old D:D is now E:E and data will paste into F:F)
2. Paste this formula in D1 of all other sheets:
=(IF(ISBLANK(F1),E1,""))
3. Scroll formula down column D as far as you will ever have data
4. Hide column D:D in all other sheets
5. In Sheet1 D1 change the formula to:
=IF(ISERROR("F"&MATCH(B1,INDIRECT((A1)&"!D:D"),0)),"NO TARGET !","F"&MATCH(B1,INDIRECT((A1)&"!D:D"),0))
6. Change the event macro code to:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 3 Then
If Range("D1").Value = "NO TARGET !" Then
GoTo ErrorHandler
Else
Application.ScreenUpdating = False
Range(Target, Target.Offset(0, 1)).Copy
Sheets(Target.Offset(0, -2).Value).Select
ActiveSheet.Range("A1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
ActiveSheet.Range("A1").Copy
ActiveSheet.Range(ActiveSheet.Range("B1").Value).Select
ActiveSheet.Paste
ActiveSheet.Range("A1:B1").ClearContents
Sheets("Sheet1").Select
Application.CutCopyMode = False
End If
End If
Exit Sub
ErrorHandler:
CutCopyMode = False
MsgBox "NO TARGET"
Exit Sub
End Sub

The formula in Sheet1 D1 still searches for a target in D:D (which is hidden). D:D replicates E:E provided F:F is blank (so only targets with nothing against them in F are shown in D:D forcing the formula to the next suitable match.

D1 in Sheet1 will display a cell reference if a free target is available. When it runs out of targets it will display "NO TARGET !". If you try to make an entry a message box warning appears and the macro exits.

This was apparantly a challenge for both me and my computer which blew its surge protector midway through an attempt at a reply!

Hope it works for you
Have fun
Derek




[ This Message was edited by: Derek on 2002-03-02 03:52 ]
Derek is offline   Reply With Quote
Old Mar 4th, 2002, 01:34 PM   #6
Skebo
New Member
 
Join Date: Feb 2002
Posts: 20
Default

Derek,
Sorry to hear about your hardware problems, but thanks for the reply.
I made one small change to IF THEN statement for the error handler. I changed:
If Range("D1").Value = "NO TARGET !" Then

to

If ActiveCell.Offset(0, 1).Value = "NO TARGET !" Then

This works great, although my orginal intent was to use paste-links, which I think would allow for changes on sheet1. With the current situation where you write the data to A1:B1, this won't work. Is there some specific reason that has to be done?




[ This Message was edited by: Skebo on 2002-03-04 12:40 ]
Skebo is offline   Reply With Quote
Old Mar 4th, 2002, 06:45 PM   #7
Derek
Board Regular
 
Join Date: Feb 2002
Location: Perth Australia
Posts: 1,567
Default

Hi again
Sorry mate but we're moving into territory somewhat ahead of my abilites now Skebo.

Look I am sure it is possible in vb to paste directly to the correct cell on the other sheet/s but my vb skills are ultra basic. I wasn't able to fully master the syntax for referencing ranges between the sheets in these circumstances. So for my skill level it was easier first to paste the data and its destination address into A1:B1 of the other sheet, then to reference it from there.

I cannot quite visualise the paste link scenario - because as it stands if you change the original data in Sheet1 Column C then the macro will immediately paste that data to the next available target in the other sheet. So I guess you should change the event that triggers the macro to doubleclick (ie when you doubleclick the data in Sheet1 Col C, it pastes to the other sheet). This will allow you to change the data to update the link without triggering the macro again.

I suggest you start a new post to get the attention of one of the vb gurus - tell them what you've got so far and see if they can improve my code to achieve what you require.
Good luck
Derek
Derek is offline   Reply With Quote
Old Mar 5th, 2002, 11:35 PM   #8
Derek
Board Regular
 
Join Date: Feb 2002
Location: Perth Australia
Posts: 1,567
Default

Skebo
Ah, I think this is what you are after. Change the event macro to this and doubleclick your data entry to activate it:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column = 3 Then
Application.ScreenUpdating = False
Sheets(Target.Offset(0, -2).Value).Range(Target.Offset(0, 1).Value).Formula = "=" & "Sheet1!" & Target.Address
End If
End Sub

good luck
Derek


[ This Message was edited by: Derek on 2002-03-05 22:49 ]
Derek is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 07:42 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes