Consulting

Results 1 to 2 of 2

Thread: Switching from one tab to another VBA

  1. #1
    VBAX Newbie
    Joined
    May 2018
    Posts
    3
    Location

    Switching from one tab to another VBA

    Hi, I'm supposed to modify one tiny chunk of codes from a long VBA Excel Macro. That tiny chunk is currently looking up one worksheet. I need it to look up another worksheet first if it exists, otherwise look at the current worksheet. Could someone suggest how to modify it? Thanks!

    workbooks (wkbk_accoun1).sheet("account1").select
    
    amount1= worksheetfunction.match("colA", rows ("5:5"),0)

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Dim Account1Exists as boolean
    Dim Sht as Worksheet
    
    Account1Exists = False
    For each Sht in Worksheets
       If Sht.Name = "account1" Then Account1Exists = True
    Next
    
    If account1Exists then 
       Sheets("Account1").Select
    Else
       Sheets("Account2").Select
    End if
    
    amount1= worksheetfunction.match("colA", rows ("5:5"),0)
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •