Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect Column B contents and shift right 1

Status
Not open for further replies.

Funkymatt

Programmer
Aug 27, 2002
101
US
All,

Given:
Cell B2 has the current day (Mon, Tues, Wed, Thurs, Fri)
Cell B3 has the full date (01/06/2003)
Cells B4:B29 have either a text Yes or a No value

Find:
On workbook load I want to check the date in cell B3 to verify that it is today’s date. If it is today's date, do nothing. If it is not, move the entire column B to column C, column C to column D, and column D to column E... and so on.

does this work for the latter most logic question?
Columns("B:B").Select
Selection.Delete Shift:=xlToLeft

If not, any suggestions?

Best,
Matt
 
Almost correct. Try

Columns("B:B").Select
Selection.Insert Shift:=xlToRight
 
I am getting the following error with the first line in my IF block??:

"Run time error '1004' Application defined or run-time defined error"

Sub InsertDate()
If Sheet1.Cells(3, B) = Date Then

Else
Sheet1.Cells(3, B) = Date
Columns("B:B").Select
Selection.Delete Shift:=xlToRight
End If
End Sub

 
This should do what you are wanting to do:
Code:
Sub InsertDate()
    If Worksheets("Sheet1").Cells(3, 2).Value = Date Then
      MsgBox "ok"
    Else
        Columns("B:B").Select
        Selection.Insert Shift:=xlToRight
        Worksheets("Sheet1").Cells(3, 2).Value = Date
    End If
End Sub
Of course, in your production version, you should probably not use "Sheet1" to find the sheet you want.

mscallisto: Date (when used without parameters) is the Excel workbook function to retrieve the current system date. It's documented in the help file.
 
Zathras,
In production I used the sheet name "GoHokies" not "Sheet1" so i'm all set :)

Thanks for your help
Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top