Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Select range & copy


Help please if possible. I have 3 columns of data on a worksheet that
need to be updated when clicking on a selection in a list box.
The first 2 columns have common data regardless of the selection. I
have created a macro for this by following key strokes for select, copy
and paste, and it works fine.
The third column however requires data specific to the selection made
in the list box. This data is in columns on another worksheet, one
column for each possible selection option, and each column having a
reference number (1 to 20) across the top. These reference numbers
correspond to the options displayed in the list box.
How do I code the next part of the macro so that when clicking the
selection in the list box the corresponding reference number is
identified on the worksheet containing the data, the data range
selected in that column, and copied to the data range in the third
column? Regards - John


--
tvac
------------------------------------------------------------------------
tvac's Profile: http://www.excelforum.com/member.php...o&userid=29347
View this thread: http://www.excelforum.com/showthread...hreadid=490566

  #2   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default Select range & copy

tvac,

I tried this:

I put a ListBox on Sheet2 -- ListBox1.
I put 4 values in J4:j8, also in sheet2.
I named those 4 cells as mSource.
I put mSource in the ListFillRange of the ListBox.

I put 4 columns, each with 4 values in Sheet1.
I put them in cells A1:D4

I put the following code in the click event of ListBox1:

Private Sub ListBox1_Click()
Dim mCol As Integer
mCol = ListBox1.ListIndex + 1
With Sheets("Sheet1")
.Range(.Cells(1, mCol), .Cells(4, mCol)).Copy
End With
Sheets("Sheet2").Range("A1:A4").PasteSpecial Paste:=xlPasteAll
End Sub

I think this does what you're looking for.

Good luck with your project.

Art

"tvac" wrote:


Help please if possible. I have 3 columns of data on a worksheet that
need to be updated when clicking on a selection in a list box.
The first 2 columns have common data regardless of the selection. I
have created a macro for this by following key strokes for select, copy
and paste, and it works fine.
The third column however requires data specific to the selection made
in the list box. This data is in columns on another worksheet, one
column for each possible selection option, and each column having a
reference number (1 to 20) across the top. These reference numbers
correspond to the options displayed in the list box.
How do I code the next part of the macro so that when clicking the
selection in the list box the corresponding reference number is
identified on the worksheet containing the data, the data range
selected in that column, and copied to the data range in the third
column? Regards - John


--
tvac
------------------------------------------------------------------------
tvac's Profile: http://www.excelforum.com/member.php...o&userid=29347
View this thread: http://www.excelforum.com/showthread...hreadid=490566


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Select range & copy


Art or anyone.
Thanks for this. I thought with my limited knowledge that I could make
it work given a bit of a lead. However, in trying to keep it simple I
omitted some info.
The ListFillRange of the listbox refers to a list of names on another
sheet, against which is a ref number. I scroll through the list and
click on the name required. (At this point the macro is activated and
the first 2 columns of data are copied over). Also through a Vlookup
the ref number for the name selected is placed in a cell next to the
listbox. So I now need to continue the macro to :
1 - Read the value of the ref number in the cell next to the listbox.
2 - Go to the second sheet containing the columns of data.
3 - Find the ref number in the row above the columns of data.
4 - Select the data range from that column.
5 - Copy and paste back to the first sheet into the third column.
Sorry to be a pain, but any further help would be appreciated.
Regards - John


I tried this:

I put a ListBox on Sheet2 -- ListBox1.
I put 4 values in J4:j8, also in sheet2.
I named those 4 cells as mSource.
I put mSource in the ListFillRange of the ListBox.

I put 4 columns, each with 4 values in Sheet1.
I put them in cells A1:D4

I put the following code in the click event of ListBox1:

Private Sub ListBox1_Click()
Dim mCol As Integer
mCol = ListBox1.ListIndex + 1
With Sheets("Sheet1")
..Range(.Cells(1, mCol), .Cells(4, mCol)).Copy
End With
Sheets("Sheet2").Range("A1:A4").PasteSpecial Paste:=xlPasteAll
End Sub

I think this does what you're looking for.

Good luck with your project.

Art

"tvac" wrote:


Help please if possible. I have 3 columns of data on a worksheet

that
need to be updated when clicking on a selection in a list box.
The first 2 columns have common data regardless of the selection. I
have created a macro for this by following key strokes for select,

copy
and paste, and it works fine.
The third column however requires data specific to the selection

made
in the list box. This data is in columns on another worksheet, one
column for each possible selection option, and each column having a
reference number (1 to 20) across the top. These reference numbers
correspond to the options displayed in the list box.
How do I code the next part of the macro so that when clicking the
selection in the list box the corresponding reference number is
identified on the worksheet containing the data, the data range
selected in that column, and copied to the data range in the third
column? Regards - John


--
tvac

------------------------------------------------------------------------
tvac's Profile:

http://www.excelforum.com/member.php...o&userid=29347
View this thread:

http://www.excelforum.com/showthread...hreadid=490566




--
tvac
------------------------------------------------------------------------
tvac's Profile: http://www.excelforum.com/member.php...o&userid=29347
View this thread: http://www.excelforum.com/showthread...hreadid=490566

  #4   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default Select range & copy

tvac,

Okay, the code now looks like this:

Private Sub ListBox1_Click()
Dim mRef As Integer
Dim mCol As Integer
mRef = Range("book2.xls!mRefList").Item(ListBox1.ListInde x + 1)
With Sheets("Sheet3")
mCol = .Range("A1:D1").Find(mRef).Column
End With
With Sheets("Sheet1")
.Range(.Cells(1, mCol), .Cells(4, mCol)).Copy
End With
Sheets("Sheet2").Range("A1:A4").PasteSpecial Paste:=xlPasteAll
End Sub

My columns are in sheet3.
The range to the left of the ListBox stuff is mColList
I changed the range name of the ListBox stuff to mRefList

mColList contains values that are in cells A1:D1 in sheet3.

I hope this helps.

Art


"tvac" wrote:


Art or anyone.
Thanks for this. I thought with my limited knowledge that I could make
it work given a bit of a lead. However, in trying to keep it simple I
omitted some info.
The ListFillRange of the listbox refers to a list of names on another
sheet, against which is a ref number. I scroll through the list and
click on the name required. (At this point the macro is activated and
the first 2 columns of data are copied over). Also through a Vlookup
the ref number for the name selected is placed in a cell next to the
listbox. So I now need to continue the macro to :
1 - Read the value of the ref number in the cell next to the listbox.
2 - Go to the second sheet containing the columns of data.
3 - Find the ref number in the row above the columns of data.
4 - Select the data range from that column.
5 - Copy and paste back to the first sheet into the third column.
Sorry to be a pain, but any further help would be appreciated.
Regards - John


I tried this:

I put a ListBox on Sheet2 -- ListBox1.
I put 4 values in J4:j8, also in sheet2.
I named those 4 cells as mSource.
I put mSource in the ListFillRange of the ListBox.

I put 4 columns, each with 4 values in Sheet1.
I put them in cells A1:D4

I put the following code in the click event of ListBox1:

Private Sub ListBox1_Click()
Dim mCol As Integer
mCol = ListBox1.ListIndex + 1
With Sheets("Sheet1")
.Range(.Cells(1, mCol), .Cells(4, mCol)).Copy
End With
Sheets("Sheet2").Range("A1:A4").PasteSpecial Paste:=xlPasteAll
End Sub

I think this does what you're looking for.

Good luck with your project.

Art

"tvac" wrote:


Help please if possible. I have 3 columns of data on a worksheet

that
need to be updated when clicking on a selection in a list box.
The first 2 columns have common data regardless of the selection. I
have created a macro for this by following key strokes for select,

copy
and paste, and it works fine.
The third column however requires data specific to the selection

made
in the list box. This data is in columns on another worksheet, one
column for each possible selection option, and each column having a
reference number (1 to 20) across the top. These reference numbers
correspond to the options displayed in the list box.
How do I code the next part of the macro so that when clicking the
selection in the list box the corresponding reference number is
identified on the worksheet containing the data, the data range
selected in that column, and copied to the data range in the third
column? Regards - John


--
tvac

------------------------------------------------------------------------
tvac's Profile:

http://www.excelforum.com/member.php...o&userid=29347
View this thread:

http://www.excelforum.com/showthread...hreadid=490566




--
tvac
------------------------------------------------------------------------
tvac's Profile: http://www.excelforum.com/member.php...o&userid=29347
View this thread: http://www.excelforum.com/showthread...hreadid=490566


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Select range & copy


Art
Great stuff. I tweeked a few things, but it works! Thanks for your
help. Regards John


--
tvac
------------------------------------------------------------------------
tvac's Profile: http://www.excelforum.com/member.php...o&userid=29347
View this thread: http://www.excelforum.com/showthread...hreadid=490566



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
select a range, copy it to a new sheet Dave F Excel Discussion (Misc queries) 1 September 22nd 06 08:06 PM
Select a range and copy to new workbook juan Excel Programming 0 July 23rd 04 11:53 PM
select date range and copy 3lad3 Excel Programming 1 July 23rd 04 02:15 PM
Select and Copy Range using Offset jondorv Excel Programming 1 May 16th 04 05:23 PM
Automatically select range and copy to new sheet Alistair[_2_] Excel Programming 3 October 11th 03 04:33 AM


All times are GMT +1. The time now is 10:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"