Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Duplicate prevention from Listbox selections to worksheet


Hi everybody,
I have a UserForm with a Multi-column listbox set to multiselect. Th
selected members from the listbox are then pasted to a range (Rng1)
The listbox has 8 command buttons which determine the RowSource.
The code works fine, but has a serious flaw. It is possible to selec
and paste an item that already exists on the spreadsheet. I need a wa
to intercept duplicates and not allow them to be entered into th
spreadsheet, and then allowing the remaining non-duplicates to go ahea
and be entered.
Using the variables in my code I need to check each ListBox1.List(i, 0
against the entries already in Rng2. Could really use some help.

Here is My Code:

Private Sub cmdEnterSelection_Click()
Dim ACol As Long
Dim Rng1 As Range
Dim Rng2 As Range
Dim i As Long
Dim j As Long
Dim Entries As Long
Dim CopyCol As Long

Application.ScreenUpdating = False
ACol = Sheets("Takeoff").Range("AlphaCol").Column
'column to copy all formulas from
Set Rng1 = Sheets("Takeoff").Range("TakeOffHeaders") '8Rowsx240Columns
Set Rng2 = Sheets("Takeoff").Range("ScopeNames") '1Rowx240column
TopRow of Rng1
Entries = Excel.WorksheetFunction.CountA(Rng2)
CopyCol = 1 + Entries
For i = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(i) Then
'Here is the logic I'm trying to code
'If Me.ListBox1.List(i,0)= Anything Already Rng2 Then Next (i)
Columns(ACol).Copy
Columns(ACol + CopyCol - 1).Select
ActiveSheet.Paste
With Rng1
.Cells(1, CopyCol).Value = ListBox1.List(i, 0)
.Cells(2, CopyCol).Value = ListBox1.List(i, 1)
.Cells(4, CopyCol).Value = ListBox1.List(i, 2)
.Cells(5, CopyCol).Value = ListBox1.List(i, 3)
.Cells(7, CopyCol).Value = ListBox1.List(i, 4)
.Cells(8, CopyCol).Value = ListBox1.List(i, 5)
.Cells(9, CopyCol).Value = ListBox1.List(i, 6)
.Cells(10, CopyCol).Value = ListBox1.List(i, 7)
End With
CopyCol = CopyCol + 1
End If
Next i
OptionButton2.Value = True
ActiveSheet.Range("E12").Select
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Su

--
Case

-----------------------------------------------------------------------
Casey's Profile: http://www.excelforum.com/member.php...nfo&userid=454
View this thread: http://www.excelforum.com/showthread.php?threadid=55110

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Duplicate prevention from Listbox selections to worksheet

Private Sub cmdEnterSelection_Click()
Dim ACol As Long
Dim Rng1 As Range
Dim Rng2 As Range
Dim i As Long
Dim j As Long
Dim Entries As Long
Dim CopyCol As Long

Application.ScreenUpdating = False
ACol = Sheets("Takeoff").Range("AlphaCol").Column
'column to copy all formulas from
Set Rng1 = Sheets("Takeoff").Range("TakeOffHeaders") '8Rowsx240Columns
Set Rng2 = Sheets("Takeoff").Range("ScopeNames") '1Rowx240columns
TopRow of Rng1
Entries = Excel.WorksheetFunction.CountA(Rng2)
CopyCol = 1 + Entries
For i = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(i) Then
'Here is the logic I'm trying to code
If Application.Countif(rng2,Me.ListBox1.List(i,0)) = 0 then
Columns(ACol).Copy
Columns(ACol + CopyCol - 1).Select
ActiveSheet.Paste
With Rng1
.Cells(1, CopyCol).Value = ListBox1.List(i, 0)
.Cells(2, CopyCol).Value = ListBox1.List(i, 1)
.Cells(4, CopyCol).Value = ListBox1.List(i, 2)
.Cells(5, CopyCol).Value = ListBox1.List(i, 3)
.Cells(7, CopyCol).Value = ListBox1.List(i, 4)
.Cells(8, CopyCol).Value = ListBox1.List(i, 5)
.Cells(9, CopyCol).Value = ListBox1.List(i, 6)
.Cells(10, CopyCol).Value = ListBox1.List(i, 7)
End With
CopyCol = CopyCol + 1
End if
End If
Next i
OptionButton2.Value = True
ActiveSheet.Range("E12").Select
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub

--
Regards,
Tom Ogilvy

"Casey" wrote:


Hi everybody,
I have a UserForm with a Multi-column listbox set to multiselect. The
selected members from the listbox are then pasted to a range (Rng1).
The listbox has 8 command buttons which determine the RowSource.
The code works fine, but has a serious flaw. It is possible to select
and paste an item that already exists on the spreadsheet. I need a way
to intercept duplicates and not allow them to be entered into the
spreadsheet, and then allowing the remaining non-duplicates to go ahead
and be entered.
Using the variables in my code I need to check each ListBox1.List(i, 0)
against the entries already in Rng2. Could really use some help.

Here is My Code:

Private Sub cmdEnterSelection_Click()
Dim ACol As Long
Dim Rng1 As Range
Dim Rng2 As Range
Dim i As Long
Dim j As Long
Dim Entries As Long
Dim CopyCol As Long

Application.ScreenUpdating = False
ACol = Sheets("Takeoff").Range("AlphaCol").Column
'column to copy all formulas from
Set Rng1 = Sheets("Takeoff").Range("TakeOffHeaders") '8Rowsx240Columns
Set Rng2 = Sheets("Takeoff").Range("ScopeNames") '1Rowx240columns
TopRow of Rng1
Entries = Excel.WorksheetFunction.CountA(Rng2)
CopyCol = 1 + Entries
For i = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(i) Then
'Here is the logic I'm trying to code
'If Me.ListBox1.List(i,0)= Anything Already Rng2 Then Next (i)
Columns(ACol).Copy
Columns(ACol + CopyCol - 1).Select
ActiveSheet.Paste
With Rng1
.Cells(1, CopyCol).Value = ListBox1.List(i, 0)
.Cells(2, CopyCol).Value = ListBox1.List(i, 1)
.Cells(4, CopyCol).Value = ListBox1.List(i, 2)
.Cells(5, CopyCol).Value = ListBox1.List(i, 3)
.Cells(7, CopyCol).Value = ListBox1.List(i, 4)
.Cells(8, CopyCol).Value = ListBox1.List(i, 5)
.Cells(9, CopyCol).Value = ListBox1.List(i, 6)
.Cells(10, CopyCol).Value = ListBox1.List(i, 7)
End With
CopyCol = CopyCol + 1
End If
Next i
OptionButton2.Value = True
ActiveSheet.Range("E12").Select
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub


--
Casey


------------------------------------------------------------------------
Casey's Profile: http://www.excelforum.com/member.php...fo&userid=4545
View this thread: http://www.excelforum.com/showthread...hreadid=551109


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Duplicate prevention from Listbox selections to worksheet


Tom,
I'm stunned. Your solution is perfect. I have spent 4 or 5 days chasing
Arrays, Collections and all manner of methods to adapt to this problem.
I still can't believe it was that simple (elegant). Thank you very
much.


--
Casey


------------------------------------------------------------------------
Casey's Profile: http://www.excelforum.com/member.php...fo&userid=4545
View this thread: http://www.excelforum.com/showthread...hreadid=551109

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
Creating Chart from Userform ListBox selections Corey Charts and Charting in Excel 2 September 8th 08 05:53 AM
How do I retrieve multiple selections from a forms listbox? Wheeler Excel Programming 2 April 21st 05 12:31 AM
Display selections from a listbox in a message box Excel-erate2004[_35_] Excel Programming 2 September 6th 04 12:48 PM
Jumping to chart based on listbox selections ChrisMD Excel Programming 0 July 7th 04 04:42 PM
changing foreground color of listbox w/o losing selections PatFinegan[_13_] Excel Programming 0 May 10th 04 09:30 PM


All times are GMT +1. The time now is 09:06 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"