#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Visual Basic

I know almost nothing about visual basic, and my supervisor asked me to add
some things into the code of a spreadsheet. I know what the code is supposed
to do, but I honestly don't know if I'm doing it right. Can someone tell me
what exactly this is doing??

Sub data()
Application.ScreenUpdating = False
For Each sht In ActiveWorkbook.Sheets
sht.Activate
ActiveSheet.unprotect
Next
Worksheets("Sheet").Visible = True
Worksheets("Data").Visible = True
Worksheets("Data").Activate
Columns("A:B").Hidden = False
region = Worksheets("Sheet").Range("Region").Value
Cells(3, 3).Select
cellcount = Range(Selection, Selection.End(xlDown)).Count
umis = 0
umiu = 0
umip = 0
mcpls = 0
mcplu = 0
mcplp = 0
gvfpls = 0
gvfplu = 0
gvfplp = 0
mshs = 0
mshu = 0
mshp = 0
bdchs = 0
bdchu = 0
bdchp = 0

These letter groups represent product lines that are being pulled from one
sheet and grouped together and placed in another sheet. I have to add another
group, but can I just add it into the code because how will excel know what
it is referencing too?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Visual Basic

Sub data()

'hide the screen flicker so you're not irritated.
Application.ScreenUpdating = False

'unprotect all the sheets in the activeworkbook
For Each sht In ActiveWorkbook.Sheets
sht.Activate
ActiveSheet.unprotect
Next

'make a worksheet named Sheet visible (maybe it was hidden??)
Worksheets("Sheet").Visible = True

'make a worksheet named Data visible (maybe it was hidden??)
Worksheets("Data").Visible = True

'select that sheet
Worksheets("Data").Activate

'unhide columns A:B of the active sheet (Data)
Columns("A:B").Hidden = False

'there's a range that has been named (via Insert|Name|Define) on Sheet
'this picks out the value of that range and stores it into a variable named
'region.
'if you select Sheet, then edit|goto and type in Region
'you'll see the range (a single cell or multiple cells) whose value
'is being put into that variable named Region
'the coder used Region in two spots--once for the range name
'and once for the variable to hold that value.
'it made it easier for him/her, but don't you get confused by it.
region = Worksheets("Sheet").Range("Region").Value

'select C3 on the activesheet (still Data)
Cells(3, 3).Select

'range(selection, selection.end(xldown))
'is the same as selecting C3 and then hitting ctrl-shift-downarrow
'if there's data under C3, it'll select C3 to the row above the first
'gap in column C
'try it manually and you'll see.
'.count is just returning the number of cells in that range
cellcount = Range(Selection, Selection.End(xlDown)).Count

'A bunch of variables are set to 0. Maybe counters??? Maybe subtotals???
'maybe costs/prices, who knows????
umis = 0
umiu = 0
umip = 0
mcpls = 0
mcplu = 0
mcplp = 0
gvfpls = 0
gvfplu = 0
gvfplp = 0
mshs = 0
mshu = 0
mshp = 0
bdchs = 0
bdchu = 0
bdchp = 0

Co-op 20 wrote:

I know almost nothing about visual basic, and my supervisor asked me to add
some things into the code of a spreadsheet. I know what the code is supposed
to do, but I honestly don't know if I'm doing it right. Can someone tell me
what exactly this is doing??

Sub data()
Application.ScreenUpdating = False
For Each sht In ActiveWorkbook.Sheets
sht.Activate
ActiveSheet.unprotect
Next
Worksheets("Sheet").Visible = True
Worksheets("Data").Visible = True
Worksheets("Data").Activate
Columns("A:B").Hidden = False
region = Worksheets("Sheet").Range("Region").Value
Cells(3, 3).Select
cellcount = Range(Selection, Selection.End(xlDown)).Count
umis = 0
umiu = 0
umip = 0
mcpls = 0
mcplu = 0
mcplp = 0
gvfpls = 0
gvfplu = 0
gvfplp = 0
mshs = 0
mshu = 0
mshp = 0
bdchs = 0
bdchu = 0
bdchp = 0

These letter groups represent product lines that are being pulled from one
sheet and grouped together and placed in another sheet. I have to add another
group, but can I just add it into the code because how will excel know what
it is referencing too?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,718
Default Visual Basic

The code you posted is doing very little but it looks like you didn't post
all of it. It's quite readable though. It unprotects all the sheets, makes
2 sheets visible, activates sheet "Data", unhides columns A and B, reads the
value of a cell named "region" into a variable of the same name, selects
cell C3, captures the count of continuous cells from entries from C3 down
into the variable "cellcount", and sets some variables to 0. So, it hasn't
actually produced anything at this point.

--
Jim
"Co-op 20" <Co-op wrote in message
...
|I know almost nothing about visual basic, and my supervisor asked me to add
| some things into the code of a spreadsheet. I know what the code is
supposed
| to do, but I honestly don't know if I'm doing it right. Can someone tell
me
| what exactly this is doing??
|
| Sub data()
| Application.ScreenUpdating = False
| For Each sht In ActiveWorkbook.Sheets
| sht.Activate
| ActiveSheet.unprotect
| Next
| Worksheets("Sheet").Visible = True
| Worksheets("Data").Visible = True
| Worksheets("Data").Activate
| Columns("A:B").Hidden = False
| region = Worksheets("Sheet").Range("Region").Value
| Cells(3, 3).Select
| cellcount = Range(Selection, Selection.End(xlDown)).Count
| umis = 0
| umiu = 0
| umip = 0
| mcpls = 0
| mcplu = 0
| mcplp = 0
| gvfpls = 0
| gvfplu = 0
| gvfplp = 0
| mshs = 0
| mshu = 0
| mshp = 0
| bdchs = 0
| bdchu = 0
| bdchp = 0
|
| These letter groups represent product lines that are being pulled from one
| sheet and grouped together and placed in another sheet. I have to add
another
| group, but can I just add it into the code because how will excel know
what
| it is referencing too?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
visual basic jiwolf Excel Worksheet Functions 2 October 8th 05 09:12 PM
Visual Basic and SP2 JessJ Excel Discussion (Misc queries) 2 October 6th 05 12:17 PM
changing the visual basic in office 2003 to visual studio net bigdaddy3 Excel Discussion (Misc queries) 1 September 13th 05 10:57 AM
Visual Basic Micos3 Excel Discussion (Misc queries) 9 June 28th 05 01:41 PM
Visual Basic Help Duncan Smith Excel Discussion (Misc queries) 1 December 3rd 04 09:13 AM


All times are GMT +1. The time now is 09:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"