Sunday, November 19, 2006

LastDayofTheWeek Function

Returns a Variant (Date) containing the date of the last day of the week either before or after the EvalDate.

Syntax

LastDayOfWeek(EvalDate,LastDay, ReturnType)

EvalDate is the date to evaluated.

LastDay is a number between 1 and 7 representing the last day for the week If omitted the value is set to 1 (Sunday)

1 = Sunday
2 = Tuesday
3 = Wednesday
4 = Thursday
5 = Friday
6 = Saturday
7 = Sunday

ReturnType is either 0 or 1. If omitted 0 is assumed. 0 returns the date of the last day of the week after the EvalDate, 1 returns the date of the last day of the week prior to the EvalDate.



Option Explicit


Public Function LastDayOfWeek(EvalDate As Date, Optional LastDay As Integer, Optional ReturnType As Integer) As Date
' Determines the date of the last day of the week based on the user's input
' EvalDate is the date to be evaluated
' LastDay is the weekday number of the last day of the week starting with
' 1 = Sunday, 2 = Monday, etc...
' ReturnType is either 0 (zero) or 1. Zero returns date of the last day of the week after the EvalDate
' 1 returns the date of the last day of the week prior to the EvalDate. If omitted zero is assumed.

Dim intEvalWeekday As Integer ' The weekday of the date to be evaluated
Dim intDifference As Integer

intEvalWeekday = Weekday(EvalDate, vbSunday)

' If the LastDay agument was omitted the value is set as 1 (Sunday).
' If the user enters a number that is not between 1 and 7 an error message
' is displayed.
If LastDay = 0 Then
LastDay = 1
ElseIf LastDay > 7 Or LastDay <>
MsgBox "Enter a number between 1 and 7 representing the day that is the last day of the week." _
& vbCr & vbCr & _
"1 = Sunday" & vbCr & "2 = Monday" & vbCr & "3 = Tuesday" & vbCr & _
"4 = Wednesday" & vbCr & "5 = Thursday" & vbCr &amp; "6 = Friday" & vbCr & _
"7 = Saturday", vbCritical
LastDayOfWeek = "Error" ' This forces an error. Otherwise the formula will display "01/01/00"
Exit Function
End If

intDifference = LastDay - intEvalWeekday

' Determine output value of the function
If ReturnType = 0 Then ' Return the date for the last day of the week that follows
the EvalDate
Select Case intDifference
Case 0
LastDayOfWeek = EvalDate
Case Is > 0
LastDayOfWeek = EvalDate + (LastDay - intEvalWeekday)
Case Is <>
LastDayOfWeek = EvalDate + (7 + LastDay - intEvalWeekday)
End Select
ElseIf ReturnType = 1 Then ' Return the date for the last day of the week that precedes
the EvalDate
Select Case intDifference
Case 0
LastDayOfWeek = EvalDate
Case Is > 0
LastDayOfWeek = EvalDate - ((7 + intEvalWeekday) - LastDay)
Case Is <>
LastDayOfWeek = EvalDate + (LastDay - intEvalWeekday)
End Select
End If
End Function

Shading Unlocked Cells

The below subs shade and unshade the unlocked cells in the active sheet. The third sub clears all the unlocked cells. When I create an application I protect the sheet and shade the cells that the users can input data into.

This is also an easy way to check what cells are unlocked.


Sub UnShade()
' Set the ColorIndex for all the unlocked cells on the
' ActiveSheet to 0.

ActiveSheet.Unprotect
Set rngLast = Range("A1").SpecialCells(xlCellTypeLastCell)
llastColumn = rngLast.Column
lLastRow = rngLast.Row
Set rngUsed = Range("A1", rngLast)
r = 1
c = 1
Do Until r = lLastRow + 1
Do Until c = llastColumn + 1
If Cells(r, c).Locked = False Then
Cells(r, c).Interior.ColorIndex = 0
End If
c = c + 1
Loop
c = 1
r = r + 1
Loop
ActiveSheet.Protect
End Sub

Sub Shade()
' Set the ColorIndex for all the unlocked cells on the
' ActiveSheet to 4.

ActiveSheet.Unprotect
Set rngLast = Range("A1").SpecialCells(xlCellTypeLastCell)
llastColumn = rngLast.Column
lLastRow = rngLast.Row
Set rngUsed = Range("A1", rngLast)
r = 1
c = 1
Do Until r = lLastRow + 1
Do Until c = llastColumn + 1
If Cells(r, c).Locked = False Then
Cells(r, c).Interior.ColorIndex = 4
End If
c = c + 1
Loop
c = 1
r = r + 1
Loop
ActiveSheet.Protect
End Sub

Sub ClearUnlockedCells()
' Clear contents of all unlocked cells in the active
' sheet.

ActiveSheet.Unprotect
Set rngLast = Range("A1").SpecialCells(xlCellTypeLastCell)
llastColumn = rngLast.Column
lLastRow = rngLast.Row
Set rngUsed = Range("A1", rngLast)
r = 1
c = 1
Do Until r = lLastRow + 1
Do Until c = llastColumn + 1
If Cells(r, c).Locked = False Then
Cells(r, c).ClearContents
End If
c = c + 1
Loop
c = 1
r = r + 1
Loop
ActiveSheet.Protect
End Sub

Update All Pivot Tables in the Active Workbook

This sub updates all the pivot tables in the active workbook.

Sub UpdatePivotTables()
' Updates all the pivot tables in the ActiveWorkbook.
Application.ScreenUpdating = False
For Each pc In ActiveWorkbook.PivotCaches
pc.Refresh
Next
Application.ScreenUpdating = True
End Sub

Saturday, October 28, 2006

Create Page Breaks in Excel

Often you might have a large table of data that needs to be grouped and printed on separate pages based on the value in a column. This procedure asks for the column containing the group by value, clears any previous page breaks, resets the page breaks and goes to print preview mode.


Sub PageBreaks()
' Place page breaks on a worksheet based on the value in
' the column specified by the user. Sets the first row
' as headers to repeat on each page and activates the
' print preview mode.


Dim strColumn As String ' Column containing the break value
Dim lRows As Long ' Rows in the used range
Dim lTitleRow As Long ' Row containing the column headers
Dim vaValue1 As Variant ' 1st value to compare
Dim vaValue2 As Variant ' 2nd value to compare
Dim l As Long ' loop counter

lRows = ActiveSheet.UsedRange.Rows.Count

strColumn = InputBox("Enter the column containing the page break information.")
' Exit the sub if the user presses cancel.
If strColumn = "" Then
Exit Sub
End If

ActiveSheet.ResetAllPageBreaks
lTitleRow = 1

For l = 2 To lRows
Cells(l + 1, strColumn).Activate
vaValue1 = Cells(l, strColumn).Value
vaValue2 = Cells(l + 1, strColumn).Value
If vaValue2 <> vaValue1 Then
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
End If
Next l

ActiveSheet.PageSetup.PrintTitleRows = "$1:$1"
ActiveSheet.PrintPreview

Range("A1").Activate

End Sub

Sunday, February 12, 2006

YubNub

YubNub is a web application that creates a "command line" for the internet. If you type a search query that does not start with a YubNub keyword you will perform a standard Google seach. On one level it is a kind of favorites menu (type "gma" and you will be taken to Gmail) and on the other it is a shortcut menu (type "gm" + an address and you will taken to the Google Maps results page for that address).

You are able to create your own commands and there are several that simply point to individual websites. Here are the most interesting commands I found during my first look, but there are many more (and many duplicates). The parameters are in square brackets.

  • g [search string] - Performs a Google search
  • gi [search string] - Performs a Google Image search
  • gm [search string] - Performs a Google Maps search
  • wp [search string] - Performs a Wikipedia search
  • bl - Launches Bloglines
  • gma - Launches Gmail
  • am [search string] - Perfoms an Amazon search
  • y [search string] - Performs a Yahoo search
  • d [search string] - Performs a Dictionary.com search
  • gym [search string] - Performs a Google, Yahoo, and MSN search simultaneously and shows the results in separate frames.
The real power here is that you can navigate to the most common sites without messing around with favorites especially if you are on a computer other than your own.

Categories:

Organizing Items In Outlook

Outlook has several ways to organize your items (emails, contacts, tasks, appointments, etc.).
  1. Create folders to "file" the items. (Like you would physical files)
  2. Associate items with contacts.
  3. Associate items with categories.
Using Folders

This is the old way of doing things. In all likelihood you will file items and not be able to find them again. (just like in the traditional filing cabinets) I have only added one folder to the standard folders already in Outlook called "Tagged Mail". I will expalin why later.

Using Contacts

When you send or receive and email or respond to a meeting request that contains someone who is in your address book (contacts) that item is automatically associated with them. When you open a contact and select the Activity tab you will see all the items associated with that contact. If you create an appointment without using the meeting request you can associate the contact with the item on the bottom right of the screen used to create the appointment. If you want to associate a contact with an email message you can do so by right-clicking on the message and selecting options.

Using Categories

Outlook comes with a bunch of categories already set up. Unfortunately, the standard mail form does not give you the option to select categories while you are creating the message. You either have to do this in the options dialog box prior to sending or do it later. Other items like appointments and contacts allow you to categorize them while you are creating them. The key to utilizing categories is to use as many categories as needed to describe the item. Don't worry about using too many, just think of the things about the item that you will think of in the future to find it. There is no need to open the categories dialog box either. Just type the categories separated by a comma. If it is on the list it will be selected, if it is not it will be added.

How to Use Categories to Find Anything

The Tagged Mail folder I mentioned earlier is used to store all mail after it has been tagged (categorized). When an email comes in that I need to respond to I tag it before responding so that my response is pre-tagged. At the end of the day I go through my Sent Items and Inbox folders and tag all the emails. Mutiple emails can be tagged at the same time by selecting them and choosing categories from the right-click menu. All tagged messages are then put in the Tagged Mail folder.

The Tagged Mail folder is arranged by the categories so when you want to look for something scroll down to one of the appropriate categories and you will find it.

It's as simple as that. I created a custom message form that allows you to categorize messages as you create or read them, but changing the default mail message form is tricky. Once I figure that out though is will save a lot of clicking.

Sunday, February 05, 2006

Waterfalls


waterfall
Originally uploaded by dmartin35.
There are hundreds of waterfalls in the Portland area. During the winter it rains all the time and every vertical surface becomes a waterfall. This is a picture I took about a year ago.

Categories:

flickr Pictures

I signed up for flickr so it will be easier to post pictures. This is one of John by the Liberty Bell during our trip to Philadelphia in December 2005.

Categories: ,

Sunday, January 29, 2006

Debbie's Idea

This link from the Freakonomics blog is a site similar to JunkLog, but is hoping to become a reliable reference for people looking for something to read. The key diffenece is that JunkLog is item-based and Debbie's Idea is author-based.
Long before the Internet was commonly available, Debbie had the idea that it would be useful to have a reference work suggesting which book of an unfamiliar author would be best to read first. Start reading an author with a poor or atypical example of his work, she observed, and you would likely never read that writer again—perhaps losing in the process a world of pleasure and knowledge. On the other hand, since there would seldom be one right book to read first, the resource would have to be a compendium of opinions.

Visit Debbie's Idea.

Categories: ,

Wednesday, January 25, 2006

Layout For This Site

I have been working on the layout for this site and using it as a way to learn more about HTML and CSS. The CSS stylesheet for this site now resides on my Geocities website. The links to the Excel Tips and Sheet Music point you to the Geocities site.

I am happy with the site enough to put it out there, but will continue to tweak it. I am interested in comments on the design.

Categories: ,

Always Check Your Work

I was updating my profile information on JunkLog and accidentally mistyped my address as dailydistraction instead of dailydistractions. Fortunately I checked the link to make sure it worked and found that by leaving the "s" off I was directed to a blog by some guy fantisizing, in some detail, about a girl he works with.

So if for some reason you found your way to that site...sorry. If you link to this site make sure the address is correct. Just remember I am distracted by many things in one day, not just one.

Finally, always check your work. The simpliest mistakes a potentially very embarassing.

Categories: ,

Technorati

I registered with Technorati which is a blog search engine. Maybe this will point some people towards this blog. I need to go now and think of some interesting things to write about.

Categories: ,

Tuesday, January 24, 2006

JunkLog

Brad from bradsucks set up a site called JunkLog to keep track of his books, CDs, and DVDs. He has now made it available to everyone. Items are added by seaching the Amazon database. (So if it's not on Amazon you can't add it.) You are then able to add comments, tags, and a rating. There is also a place to indicate that the item is finished (books) and the date finished.

You can see if anyone else has listed an item and look to see what is on their list. Hopefully, you will find some other interesting things you may have never found on your own.

It is modeled after del.icio.us which is designed to help you organize favorites (bookmarks). You can see the items I have listed by visiting my page. I am also going to put a link on the sidebar to my page.

Categories: ,

Tuesday, January 17, 2006

Bloglines

For some reason Bloglines keeps changing my default language to Japanese (or German). I am still able to read the feeds but all the menu options are in Japanese which shows up on the screen as ???. This happened for the 2nd time today so I am going to try out Google Reader and see how it works.

UPDATE (1/25/06): Google reader is OK, but I like Bloglines better.

Categories: ,

Friday, January 13, 2006

Using del.icio.us Tags as Categories

After messing around with categories I have decided to go with this method from Fresblog. I mentioned this method before. The method I tried first ended up being too much work, because all the links in the sidebar had to be hand-coded. This technique uses a del.icio.us account to categorize the entries. I also found a JavaScript snippet that keeps an updated list of the categories in the sidebar.

Categories: ,

Friday, January 06, 2006

Making Playlists for TiVo

Whether you are an Apple fan or not iTunes is a good program. I use iTunes to help me organize my music and ensure the tag information is correct. I also use it to make my playlists. The playlists are generated by an Excel program I created. I am giving the steps here but the program is not bullet-proof. I may post it later when I make it presentable.
  1. Create a playlist in iTunes.
  2. Right-click on the playlist and select "Export Song List..."
  3. Select a name and location for the file.
  4. Open Playlist application (Excel program).
  5. On the Info page make sure the "Save Playlist Files To:" box is filled in.
  6. Press the "Playlist from iTunes".
  7. You will be asked to find the song list that was exported from iTunes. Remember that it is a text file so if you don't see it in the folder check the filetype to make sure "All Types" is selected.
  8. The playlist will be created and placed in the folder you specified on the info page. If there is already a playlist by the same name you will be asked if you want to overwrite it.
Categories: ,

Organizing Music for TiVo

The TiVo Digital Music Player is well designed in it's simplicity. All you do is tell the TiVo Desktop the root folder containing your music and it will allow you to access the files excacly as you would see them on your computer. Unlike iTunes or Windows Media Player TiVo offers no help in organizing your music so a little file maintenance may be in order. This is how I set my music up to reduce the clicking to get to what I want to hear.

Most of my music is considered rock so I placed all the non-rock music in separate folders and prefixed the folder with 1 (e.g. 1 Classical, 1 Country, 1 Jazz). This keeps these folders together and at the top of the folder list. I also created a called "0 Playlists" to house the playlists. The 0 keeps this folder at the very top of the folder list. If you have a lot of music then playlists are the best way to listen to a variety of music. I am going to take about how I make playlists later.

Categories: ,

Troubles with Galleon

As I mentioned before I have been trying different ways to stream music to my entertainment system from my computer. After messing around with Galleon I started having trouble with it not properly reading tag information so the wrong song would be listed on the screen during playback.

At the same time TiVo rolled out a newer version of their software that added several features. They include Yahoo!Photos, Yahoo!Weather, Yahoo!Traffic, Fandango movie showtimes, Live365 streaming, podcasting subcriptions.

So I scrapped the Galleon and am using the TiVo interface exclusively.

Categories: ,

Thursday, January 05, 2006

Creating Categories in Blogger

Blogger does not offer any native way to categorize blog posts. After a little research I found a couple of work-arounds. One was to use deli.cio.us to save each post as a favorite and categorize them there. Another, simplier way is to use the google blogsearch feature.

The first step is to decide where to place the category. One option is to place it in the post title (Music: Playing MP3s or Playing MP3s (Music)). The problem with this is the category names need to short so they do not clutter up the post titles. Doing this creates more generic categories that will return some unrelated items.

I created a template for new posts that gives me the ability to categorize the post before I start writing. I used the following code in the template:

<p class="category">Category: </p>

I place the category after the colon in the above. In the template I assigned the category class of the p tag to be smaller than the rest of the text make it look like it is a built-in feature.

In the sidebar there is a link for each category that searches my blog for that name.

Categories: ,

BlogRoll

I spent most of the day today learning how to customize the Blogger template. Blogger does not have any automated support to manage/update/listing links in the sidebar.

Initailly I used a piece of code genreated by Bloglines that created a list of the blogs I am subscribed to. There were two problems. I was not able to format the resulting links to look like the others on the page and there are a lot of blogs I monitor that are not often updated. I did not like the long list cluttering up the sidebar. I removed the list of links and placed one called "Blogs I Read" so only the interested will see the list and I will be automatically updated as I add and delete blogs fromt he list.

If I want to add other "permenent" links I can code them by hand.

Categories: ,

Pandora

I stumbled across Pandora the other day after reading an article in Fast Company. Pandora is an internet radio station with a twist. The founders claim they have discovered music's DNA and a working feverishly to classify music using their criteria. The result is that you can select an artist or song and Pandora will create a custom radio station playing music with a similar DNA. As songs play you can rate them to further refine the playlist.

After you create the station you can add other artists or songs to broaden the types of music played. You can also rate the songs as they are playing to narrow or widen the station's music.

You are able to have up to 100 stations at one time. There is a free option that means you will have some advertising, but it has not been implemented yet so there is no telling how intrusive it will be. The pay service is only $36 a year.

Categories: ,