LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 121
Default for next loop problem

I am trying to use the following code to identify users choice from
listbox, compare it to ws in master wb, when the users choice and the
master ws names are the same, I want to copy the ws from the master ws,
but what happens is the loop keeps cycling thru all the worksheets,
going right past the matching ws name.I've tried restructuring the lines
of code in the loop but I cannot get it to take the matched name, found
= true, and ws.copy.
Could someone please check my code and see where I am messed up?
Also, when you do ws.copy, does it copy the worksheet to the office
clipboard? I have looked at the clipboard and all that is there is the
line ws.copy and when i paste it, that's all i get ;o (

Public Sub lbVendor_Click()
Dim fname As String, spath As String
Dim wb As Workbook, ws As Worksheet
Dim found As Boolean

With lbVendor
fname = .List(.ListIndex) 'capture the value of the list index#
selected
Debug.Print fname
If obHouse Then
spath = "C:\Pricing\House\"
ElseIf obDan Then
spath = "C:\Pricing\Dan\"
ElseIf obEdwin Then
spath = "C:\Pricing\Edwin\"
ElseIf obJeff Then
spath = "C:\Pricing\Jeff\"
ElseIf obJohn Then
spath = "C:\Pricing\John\"
End If
Debug.Print spath
End With

Workbooks.Open spath & fname
Workbooks.Open "c:\Pricing\Outlook Master Pricing.xls"

found = False
For Each ws In Worksheets
If ws.Name = fname Then
found = True
Exit For
End If
'Next ws
If found = True Then
ws.Copy
End If
Debug.Print ws.Name
Next ws
End Sub

Thanks a lot for your time and consideration of my problem
Joanne
 
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
Loop Problem smandula Excel Programming 2 April 6th 06 02:45 PM
Loop problem Shawn Excel Programming 3 September 12th 05 11:05 PM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM
For...Each Loop Problem SuperJas Excel Programming 4 April 2nd 04 05:01 AM
loop problem joao Excel Programming 4 November 6th 03 02:01 PM


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