PC Review


Reply
Thread Tools Rate Thread

Copy data from list box to sheets

 
 
Mark
Guest
Posts: n/a
 
      18th Jun 2009
Hi,
I’m trying to get the data that I retrieve from a list box to copy to sheet
2 (“Fall’)in Excel2007. Currently, the code works correctly for populating
sheet1, but I only want columns A & B to appear on sheet2. The code below was
supplied by Ron de Bruin, that I have tweaked to fit my variables. Can anyone
help me with making this work? Thanks.
Mark

Private Sub CommandButton1_Click()
Dim RowNdx As Long
Dim ColNdx As Integer
Dim SaveColNdx As Integer
Dim wkbk As ThisWorkbook
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
ColNdx = 1
RowNdx = 13

For X = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(X) = True Then
Cells(RowNdx + 1, ColNdx).EntireRow.Insert
Rows(RowNdx).Copy
Rows(RowNdx + 1).PasteSpecial Paste:=xlFormats
Application.CutCopyMode = False
Cells(lastrow + 1, ColNdx).Select
' display the Selected item.
Cells(RowNdx, ColNdx).Value = ListBox1.List(X)
If Worksheets(1).Name <> "Fall" Then

For t = 2 To ActiveWorkbook.ActiveSheet.UsedRange.Columns.Count
With Cells(RowNdx, t)
.Formula = "=vlookup(" & Cells(RowNdx, ColNdx).address _
& ",'" & studentPath & "[" & studentFile & "]" & grade &
"'!A:Z," & t & ", 0)"
.Value = .Value
End With
Next t
With Worksheets("Fall")
.Cells(RowNdx + 1, ColNdx).EntireRow.Insert
.Cells(RowNdx, ColNdx).EntireRow.Copy
.Cells(RowNdx + 1, ColNdx).EntireRow.PasteSpecial Paste:=xlFormats
Application.CutCopyMode = False
.Cells(RowNdx, ColNdx).Value = ListBox1.List(X)
End With

End If
RowNdx = RowNdx + 1
End If
Next X
If Worksheets(1).Name <> "Fall" Then
Rows(RowNdx).Delete Shift:=xlUp
End If
Worksheets("Fall").Rows(RowNdx).Delete Shift:=xlUp
Unload Me
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
vb code to copy and list selected row to diff sheets pvkutty Microsoft Excel Misc 1 17th Feb 2010 12:05 PM
copy sheets & name them from list Robert Microsoft Excel Programming 3 24th Jul 2009 12:04 AM
you cannot copy or move a group of sheets that contain list ERROR postmac Microsoft Excel Crashes 0 10th Dec 2008 03:12 PM
Copy from various sheets and create a master list. J.W. Aldridge Microsoft Excel Programming 5 6th Oct 2006 06:23 PM
Copy multiple sheets using a list box kev_06 Microsoft Excel Programming 1 2nd Jun 2006 11:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:05 AM.