![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | ||||||||
|
New Member
Join Date: Apr 2002
Posts: 25
|
Hello,
Lets say i have a combobox on 'Sheet1'!B2 which lists the values in range 'Sheet2'A1: 'Sheet2'!A50. Sheet 2 looks someting like this
the user can select the combobox on sheet1. In this case this would be fred. Now comes the question: How can i make excel (when fred is selected) to copy the cells 'Sheet2'!A2:'Sheet2'!D2 to 'Sheet1'!C2:'Sheet1'!F2 ???? Thus what i want to know is how to copy a range of cells when a certain item in the listbox is selected. Anyone that has excel wisdom enough to break this problem? Thanks. [ This Message was edited by: friso on 2002-04-04 07:07 ] |
||||||||
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Location: Where the wild roses grow
Posts: 285
|
Yep, put this in your Combobox change event:
application.screenupdating=false If ComboBox1.Value = "Fred" Then Worksheets("sheet2").Range("a2:d2").Cut Worksheets("sheet1").Range ("c2:f2").Select ActiveSheet.Paste End If application.screenupdating=true End Sub There's probably an easier way as well but I am very, very drunk |
|
|
|
|
|
#3 |
|
New Member
Join Date: Apr 2002
Posts: 25
|
Thanks,
However i have a randge of 50 items in the listbox which names are not known in advance. |
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
Try the following:
Make Sheet1!C2 the linked cell to the combobox and make the input range Sheet2!A1:A50. Then in cell Sheet1!D2 put the following formula: =VLOOKUP(Sheet1!$C$2,Sheet2!$A$1:$D$50,2,FALSE) Then in cell Sheet1!E2 put the following formula: =VLOOKUP(Sheet1!$C$2,Sheet2!$A$1:$D$50,3,FALSE) Then in cell Sheet1!F2 put the following formula: =VLOOKUP(Sheet1!$C$2,Sheet2!$A$1:$D$50,4,FALSE)
__________________
Kind regards, Al Chara |
|
|
|
|
|
#5 |
|
New Member
Join Date: Apr 2002
Posts: 25
|
Hi Al,
The function gives an error..any suggestions. With error i mean excel does not accept the statement at all. thanks |
|
|
|
|
|
#6 |
|
New Member
Join Date: Apr 2002
Posts: 25
|
Al this code is accepted but it gives an #NA
in cellD2: =VLOOKUP(C2;'Sheet2'!A2:A50;2;FALSE) |
|
|
|
|
|
#7 |
|
New Member
Join Date: Apr 2002
Posts: 25
|
sorry i meant i put this code in:
=VLOOKUP(C2;'Sheet2'!A2:D50;2;FALSE) still get an #NA though |
|
|
|
|
|
#8 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
Make sure that C2 is the comboboxes linked cell. Go into design mode and right click on the combobox. Fill in C2 in the LinkedCell field.
__________________
Kind regards, Al Chara |
|
|
|
|
|
#9 |
|
New Member
Join Date: Apr 2002
Posts: 25
|
it is the linked cell, still nothing i'm affraid. Value of C2 = 1 (which i selected of course.
|
|
|
|
|
|
#10 |
|
Board Regular
Join Date: Feb 2002
Posts: 1,802
|
try using =INDEX(Sheet2!A2:D50,C2,1) in D2 instead of VLOOKUP, does that help?
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|