PDA

View Full Version : Switching from one tab to another VBA



hhn
06-08-2018, 02:41 PM
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)

SamT
06-08-2018, 03:03 PM
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)