Excel VBA Basics #7 - Using specific sheets, Hiding, Unhiding and Selecting with VBA

Excel VBA Basics #7 - Using specific sheets, Hiding, Unhiding and Selecting with VBA


In this episode, we learn that macros can affect ANY worksheet, regardless of which one you're currently in. We learn how to control and direct the code toward a specific sheet so that our data isn't overwritten on the ACTIVESHEET. By default, excel vba will throw your Range() or Cells() object on the current sheet (Activesheet), but harnessing the power of Thisworkbook.sheets() will prove very effective.

We'll even show you how to read and write on a HIDDEN worksheet. We also show how to programmatically hide or unhide a worksheet using VBA and selecting whatever sheet to be viewed.

**Limited Offer** Learn to Make Excel Do Your Work For You with The Ultimate Excel Programmer Course – Get the Full 9+ Hour Premium Course for 75% off using coupon code: https://www.udemy.com/ultimate-excel-... Click Now to Order and get Lifetime Access to Course, Workbooks, Updates and Support!
------------------------
Create Your Own Barcode Lookup System Using Excel VBA. Learn to Make Your Own Barcode Labels the Easy way and have fun with Barcode Scanners to Automate your Workflow! In this project-driven Course, you’ll learn to Build your own Custom Inventory System with Step-By-Step video instructions. This goes in depth into some advanced Userform strategies that you can use for your other projects to come. A great weekend study! YouTube Subscibers only pay one forth! Get your 75% off Coupon here: https://www.udemy.com/barcodes-excelv...
------------------------
Too busy to Learn Piano? Use my Secrets and Play Your Favorite Songs Today! Did you know; You can learn 4 basic chords in about 5 minutes and instantly be able to play millions of songs. Seriously, check this course out. 75% off for my YouTube Friends! Click here: https://www.udemy.com/play-piano-by-e...

For Articles, Updates and to Contact me for Consulting or just to drop me a line, please visit http://www.ExcelVbaIsFun.com

Here is my link to download my FREE workbooks, past present and future: https://www.dropbox.com/sh/nwc5trm2xw...

------------------------
Playlists:
Excel Vba Basics http://www.youtube.com/watch?v=AIhKNN...
Tips N Tricks https://www.youtube.com/playlist?list...
Userforms https://www.youtube.com/playlist?list...
Sample Excel Programs https://www.youtube.com/playlist?list...
Events Series https://www.youtube.com/playlist?list...
Activex Controls https://www.youtube.com/playlist?list...
------------------------

Grab an Excel Nerd T-Shirt or Hoodie:
http://ExcelVbaIsFun.spreadshirt.com/

------------------------
Interact and Follow me on:
LinkedIn: http://www.linkedin.com/in/danielcstrong
Facebook: https://www.facebook.com/Excelvbaisfun/
Twitter: https://twitter.com/ExcelVbaIsFun
Google Plus+: http://www.google.com/+ExcelVbaIsFun


'Royalty Free Music by http://audiomicro.com/royalty-free-mu...
Closed Caption:

welcome back youtubers this is daniel
strong with excel vba is fun and this
lesson we're going to go back to our
code that we were doing earlier
however today we are going to talk a
little bit about that this workbook that
sheets property
one thing i want to show you is if if we
run this macro so i'll hit alt f eight
and let's run
test one that's the one that we did to
autofill this stuff with them a few
details there
so if we run that we see that it works
just fine however what if we all wanted
to confine that to this worksheet and if
i click on sheet2 and hit all f8 and i
run it right now the way we set it up
it's going to work it's going to
automatically work no matter what sheet
i have on
so what we want to do is we want it to
only happen on sheet1 no matter where
I'm click that and over what cell and
clicked on or what worksheet is open and
this'll blow you right not even at won't
even matter if the sheet is hidden or
not so let's experiment with that a
little bit
right right now will give sheet1 name
will call it my report
okay that's our sheet one's name is my
report
we're going to go back to visual basic
alt f 11 ok so test one is our macro
will stick with that name for now and
we're going to change anything other
than
and we are going to and we're going to
hard code the name of the sheet in it
so to do that I'm going to show you you
can use the sheets property by typing
sheets and open parenthesis and we're
going to also give some space here for
now to do a quote you type in the name
of the sheet that you gave it
we gave it my report in quote in
parentheses want to say sheets my report
. cells x 1 block
so that's that's a preliminary step that
will only get so far if you have several
workbooks open you accidentally click on
the other one and you run the macro it
might write over what you have on their
second workbook with that macro
so i take an additional precaution you
probably don't have to do this
I i say this workbook . sheets my report
sales blah blah blah and I do that a few
more times i'm probably end up copying
and pasting this work like that sheets
my report and later we'll show you how
you can actually save yourself a lot of
time by giving that declaring are
setting a variable name to the sheet
name and then you can just are you a
shortened version of this to represent
this work with that sheets my report
so anyway I will go ahead and copy that
for the time being
before the word cells copy with the .
and this work for that sheets blah blah
so this time each code that runs is
going to run on the sheet my report no
matter where I'm selected at so let's
try that
I'm gonna go to sheet2 and i'm going to
hit alt f 8 i'm going to go ahead and
run my code and sure enough it looks
like it wrote it on the correct sheet
let's check it out and it did
okay just forget measure will go to
sheet3 all that fate
double click here and it ran on my
report
so that's pretty cool what else have we
got here is let's even let's even go
ahead and hide it i will right click
here and click on hide and so now
they're the sheet called my report is
hid all the fate
we're going to run it anyways
double-click let's unhide right click on
one of these unhide it son had my report
and sure enough it ran
regardless of whether it was visible you
can't do that in regular ol excel click
around
so that's why vb is so important it will
run in the background it will run it
visibly just for fun let's go ahead and
do something here
let's take this workbook that sheets my
report . visible equals false
that's just going to hide this sheet is
not going to make it super hidden soup
really a very hidden is a state where
the worksheet will not will not be
visible must use visual basic to show it
again
we're just going to make it hidden but
where you can still right click and
unhide it
so we've modified the code to hide the
sheet every time this code is run
let's try that will be fun all f eight
and we'll run test 1 and if it works at
the end of the code it will hide the
sheet for us
let's run it BAM it's hidden so it's
unhide my report
ok so that was fun let's make another
macro to to make it visible again will
come down here and we'll call this one
oops we'll call this one unhide sheet so
sub unhide will call on hide my report
ok so i have to do is we'll put a code
that says this work that sheets . or
whatever my report not visible equals
true
a lot of times you'll see this somebody
is going to be true or false
it's called boolean
so a lot of these properties the visible
property of the sheet called my report
is now going to be true and we run this
one
previously we turned it to be visible
property to be false and that's what
makes it go invisible so pretty cool
let's try it let's click
let's first of all were from any sheet
here will run the code all the fate will
go to test one that was our first code
sure enough it hit it
now we'll hit alt f eight that's unhide
my report
I'm a double click here and sure enough
it done hit it
it did not select it because we were on
sheet2 at the time when we ran it if we
wanted to unhide it and then immediately
selected we would do this with our code
let's go to this code here will say this
workbook that sheets my report . select
and that's the code - oops that's the
coaches have excel select that sheet
so rather than unhiding at the jumping
fact sheet to it will actually select it
let me just hide it for good measure all
tough 81 hide my report and selected
incidentally let's go and run that
Shazam it ended and selected that sheet
so that those some nifty codes you use
okay that's about it for this video on
the next segment we're going to talk
about declaring variables which is
important especially whenever you're
setting objects like the worksheet we
want to
we'll talk about shortening that save
your fingers a lot of keystrokes
we'll also talk about
well we'll get to that when we get to it
after i was going to say
i will talk about this properties menu
down here we're going to talk about
renaming some of these things and then
eventually we'll get to some work sheet
of inch this workbook events and we'll
get to user forms at some point in time
thank you so much for viewing
god bless

Video Length: 08:21
Uploaded By: ExcelVbaIsFun
View Count: 79,633

Related Software Products
Working With Worksheets In VBA
Working With Worksheets In VBA

Published By:
Dave Hawley

Description:
PDownload contains 2 Workbooks. One for 97-2003 users and one for 2007 users. PYou will learn how to: Add Worksheets , Add Worksheets in Month Order , Add Sheets in Numeric Order , Sort Excel Sheets/Worksheets , How To Reference Sheets , Delete Sheet Event Code , Run VBA Macro Code On Protected Sheets , Unprotect Or Protect Sheets In One Go , Group/Sort Sheets By Tab Color , Hiding Sheets In Excel , Loop All Worksheets/Sheets in Workbook & Apply Code , Return Sheet Tab Name To ...


Related Videos
Excel VBA Introduction Part 6 - Worksheets, Charts and Sheets
Excel VBA Introduction Part 6 - Worksheets, Charts and Sheets

By Andrew Gould Previous video - Selecting Cells (Range, Cells, Activecell, End, Offset) http://www.youtube.com/watch?v=c8reU-... http://www.wiseowl.co.uk - In order to navigate a workbook using VBA it's essential to understand how to refer to, activate and select the various types of sheet. This video explains the difference between worksheet, chart and sheet objects and also demonstrates how to select, copy, move, delete and rename them. You'll also see how to ...
Video Length: 40:19
Uploaded By: WiseOwlTutorials
View Count: 119,600

Automate Copying of Column Data from Sheet to Sheet Using Excel VBA
Automate Copying of Column Data from Sheet to Sheet Using Excel VBA

How to automate copying of column data from one worksheet to another using Excel VBA. Complete code and sample file available here: http://www.exceltrainingvideos.com/automate-copying-excel-column-data-from-sheet1-to-sheet2-with-vba/
Video Length: 13:02
Uploaded By: Dinesh Kumar Takyar
View Count: 108,323

Excel VBA ActiveX Controls #1 Worksheet Button and Textbox
Excel VBA ActiveX Controls #1 Worksheet Button and Textbox

Using a Button and a Textbox directly on a worksheet to invoke some simple VBA code. In this lesson, we show the user how to access the Design mode in the Developer ribbon. Design mode allow you to resize/reshape ActiveX items and right-click,Properties to edit properties. We also give the button and textbox a custom name and watch how excel utilizes that name. **Limited Offer** Learn to Make Excel Do Your Work For You with The Ultimate Excel Programmer Course – Get the ...
Video Length: 07:04
Uploaded By: ExcelVbaIsFun
View Count: 79,699

Consolidate Data from Multiple Excel Workbooks using VBA
Consolidate Data from Multiple Excel Workbooks using VBA

We can consolidate data from multiple Excel workbooks using VBA. This automates the complete process of data consolidation or summation. The process of consolidating data from different workbooks involves the following steps: (1) First we write the code for displaying the headers or labels like 'Item' and 'Quantity'. We also write the code to display the item names on the left below the header 'Item'. (2) Next we write the code to open all the workbooks from which we wish ...
Video Length: 10:32
Uploaded By: Dinesh Kumar Takyar
View Count: 60,852

Create a New Sheet and Rename Worksheet using VBA in Excel 2010
Create a New Sheet and Rename Worksheet using VBA in Excel 2010

This video shows how to programmatically Create a New Sheet and Rename Worksheet using VBA in Excel 2010 hr / bClosed Caption:/b in this video I'll be showing how we can use vba programming in Microsoft Excel 2010 to create a brand new worksheet inside your work your workbook and also renamed that worksheet to whatever name of of of your preference so let's go ahead and get started one of the first things I'm going to do is ...
Video Length: 07:30
Uploaded By: Alex Cantu
View Count: 57,663

Extract data from one worksheet to another using advanced filter with VBA
Extract data from one worksheet to another using advanced filter with VBA

Our Excel training videos on YouTube cover formulas, functions and VBA. Useful for beginners as well as advanced learners. New upload every Thursday. For details you can visit our website: http://www.familycomputerclub.com/ext... We can easily and quickly extract data from one Excel worksheet to another using advanced filter. We can also attach the process to a command button using VBA to automate the complete process of data extraction from one worksheet to another.
Video Length: 14:20
Uploaded By: Dinesh Kumar Takyar
View Count: 53,468

Compare two Excel Worksheets Cell by Cell Using VBA
Compare two Excel Worksheets Cell by Cell Using VBA

How do you compare two worksheets cell by cell in the same workbook or in different workbooks? Excel VBA provides an elegant solution. First we define a few variables that can count the rows and columns so that we know how many cells are in use in the Excel worksheets. Next we assign the used ranges to the sheet with the maximum values. Now using a nested 'for loop' we access each cell in the used range and compare them. If the cells values are not equal we write them into a new ...
Video Length: 11:14
Uploaded By: Dinesh Kumar Takyar
View Count: 46,535

Find data in specific cells in multiple worksheets using VBA
Find data in specific cells in multiple worksheets using VBA

Glenn wants to find data in specific cells in multiple worksheets using VBA and finally create a report automatically. This Excel VBA code or macro can be quite helpful in a variety of situations. We create a command button on Sheet1 and code it to select a specific cell, capture its value, assign it to a variable, select the Report Sheet, paste the value in a specific cell after finding the first empty row, go back to the next sheet and in this manner select and copy all relevant values ...
Video Length: 14:05
Uploaded By: Dinesh Kumar Takyar
View Count: 34,278

Protect Worksheet and Allow Specific Cells Editing Using Excel VBA
Protect Worksheet and Allow Specific Cells Editing Using Excel VBA

Often you wish to help the data entry operator by protecting formulas and cells in an Excel worksheet and allowing only certain areas of the worksheet for data input or editing. You can do this using standard methods as described here: http://www.familycomputerclub.com/exc... Or, you can use use Excel VBA if you are planning to automate your project as shown in this training video. More details here: http://familycomputerclub.com/protect...
Video Length: 06:52
Uploaded By: Dinesh Kumar Takyar
View Count: 33,466

Excel VBA Basics #31 Send Sheets Straight to Printer using PrintOut Method
Excel VBA Basics #31 Send Sheets Straight to Printer using PrintOut Method

Rather than triggering a print preview, sometimes you'll just want your report or sheet to go straight to the printer. With this trick, you can set it up on a worksheet, userform or in your actual report code, but you can send how many copies of whatever you want straight to the printer without any extra unnecessary clicks. Check it out!! **Limited Offer** Learn to Make Excel Do Your Work For You with The Ultimate Excel Programmer Course – Get the Full 9+ Hour Premium Course for 75% ...
Video Length: 14:31
Uploaded By: ExcelVbaIsFun
View Count: 30,336

Copyright © 2025, Ivertech. All rights reserved.