Excel VBA Code Problem

abdullahsikandar

Board Regular
Joined
Feb 10, 2014
Messages
52
Hello......


Can you all tell me please how do i select one sheet from 2 sheets in excel.

For example:

I need to select to search for a name of sheets from 3 sheets.

Worksheets("Seet2" or "Seet4")
Can i do like that?
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
What exactly are you trying to do?

Depending on what you are trying to do, you may need to select them one at a time. You could do this is a loop, i.e.
Code:
    Dim ws As Worksheet
    
    For Each ws In Worksheets
        If (ws.Name = "Sheet2") Or (ws.Name = "Sheet4") Then
            ws.Activate
            ' [I]your code here[/I]
        End If
    Next ws
 
Upvote 0
Set oWS(i) = oWB(i).Worksheets("Hello")

I am setting this to take only sheet Hello and i need it to take either the sheet Hello or sheet Hi.
 
Upvote 0
Why? What are you trying to do with it? What is the "end goal" here?
If oWS is a worksheet variable, I don't believe it can be set to multiple worksheets simultaneously.

If we know what you are trying to accomplish, we may be able to suggest alternatives.
 
Upvote 0
Why? What are you trying to do with it? What is the "end goal" here?
If oWS is a worksheet variable, I don't believe it can be set to multiple worksheets simultaneously.

If we know what you are trying to accomplish, we may be able to suggest alternatives.


Well, I am Importing all the excel files into the Database, So what i need is that when it is importing from excel so it will search from 2 sheets which one sheet name is available it will take the data from anyone of them.
 
Upvote 0
Well, I am Importing all the excel files into the Database, So what i need is that when it is importing from excel so it will search from 2 sheets which one sheet name is available it will take the data from anyone of them.
I don't think that is quite clear, probably because we do not know the details of your project like you do.

All what Excel files? Is there a folder full on Excel files you are importing?
Into what Database? Is the Database in Excel, Access, SQL, etc?
Are you searching sheets on the file you are copying FROM, or the database you are copying TO?
What exactly are you searching for, and what are you doing with it when you find it?
 
Upvote 0

Forum statistics

Threads
1,214,786
Messages
6,121,546
Members
449,038
Latest member
Guest1337

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top