Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 132,301 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,011 people online right now. Registration is fast and FREE... Join Now!




VBA - Ignore if sheet name is equal to..

 
Reply to this topicStart new topic

VBA - Ignore if sheet name is equal to..

KG87
post 22 Feb, 2008 - 06:53 AM
Post #1


D.I.C Head

**
Joined: 25 Sep, 2007
Posts: 52



Thanked 2 times
My Contributions


Getting to the end of my course now, and im having uber problems with this bit,

CODE


For i = 1 To Sheets.Count
    
    If Sheets( i ).Name = "Food" or "Drink" Then
    Next i
    
    Else
    
         frmMain.cboTable.AddItem Sheets( i ).Name
    Next i
    
    End If



I need it so if the name of the worksheet is food or drink then it isnt added to cbotable, but i get the error next without for.

Thanks in advance

George (KG87)
User is offlineProfile CardPM

Go to the top of the page

LookNAO
post 22 Feb, 2008 - 06:56 AM
Post #2


D.I.C Head

**
Joined: 28 Dec, 2007
Posts: 66



Thanked 1 times
My Contributions


You are close...

try this:

CODE

For i = 1 To Sheets.Count
    
    If Sheets( i ).Name = "Food" or "Drink" Then
                   exit for
    Else
         frmMain.cboTable.AddItem Sheets( i ).Name
    End If
next i


Now, this will exit the loop if it finds Food or Drink...
If you don't want that then:

CODE

For i = 1 To Sheets.Count
    
    If Sheets( i ).Name = "Food" or "Drink" Then
    Else
         frmMain.cboTable.AddItem Sheets( i ).Name
    End If
next i

User is offlineProfile CardPM

Go to the top of the page

KG87
post 22 Feb, 2008 - 07:03 AM
Post #3


D.I.C Head

**
Joined: 25 Sep, 2007
Posts: 52



Thanked 2 times
My Contributions


Thanks for such a quick response!

but the 2nd one (which is what i want)

CODE

For i = 1 To Sheets.Count
    
    If Sheets(i).Name = "Food" or "Drink" Then
    Else
         frmMain.cboTable.AddItem Sheets(i).Name
    End If
next i


the combo box remains empty after running that sub.

once again thanks

once i've completed this project, i'd love to share it tongue.gif
User is offlineProfile CardPM

Go to the top of the page

KG87
post 24 Feb, 2008 - 12:42 PM
Post #4


D.I.C Head

**
Joined: 25 Sep, 2007
Posts: 52



Thanked 2 times
My Contributions


sorry for the urgency, but im nearly at the end of the assignment, and this is crucial to it..

please i pray thee gods of code smile.gif
User is offlineProfile CardPM

Go to the top of the page

LookNAO
post 25 Feb, 2008 - 09:45 AM
Post #5


D.I.C Head

**
Joined: 28 Dec, 2007
Posts: 66



Thanked 1 times
My Contributions


I am sorry... I did not fully understand what you were trying to do.
When you do "additem" to a combo box it will just add it to the dropdown.

Try setting the .text ....

CODE

For i = 1 To Sheets.Count
    
    If Sheets(i).Name = "Food" or "Drink" Then
    Else
         if  frmMain.cboTable.text ="" then
               frmMain.cboTable.text = Sheets(i).Name
               frmmain.cboTable.refresh
         end if

         frmMain.cboTable.AddItem Sheets(i).Name
    End If
next i



Is this what you are looking for????
User is offlineProfile CardPM

Go to the top of the page

Realcoder
post 26 Feb, 2008 - 10:52 PM
Post #6


New D.I.C Head

*
Joined: 26 Feb, 2008
Posts: 5

{Post Removed}

This post has been edited by PsychoCoder: 26 Feb, 2008 - 11:54 PM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 01:48AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month