VBA To Hide Rows If Date In A Cell Less Than Today On Workbook Open
Apr 30, 2013
I'm trying to create a workbook which has dates in column B, starting with row 10. I'd like to have a code which will hide the rows if the date is less than today upon workbook open. This would need to apply to worksheet1 only.
My spread sheet is a church offering register that is used to record weekly contributions. Column A contains the names of the individual contributors. Columns B through BA are used to record the weekly contributions for each of the 52 weeks of the year. Row 1 of columns B through BA contains the Sunday date MM/DD/YYYY. I would like to have a macro that would scan those cells looking for a date < today. If that condition is true, I would like to hide that column. When date = today or date > today the macro can end. The goal is to have display the current week's column immediately following Column A.
I have the current code that opens our raw data file and copys it into my workbook. However it now turns out the file is saved everyday as a new file with todays date on the end. Here is my current code:
I managed to create some code that will connect to a workbook and take the data from there.
It is kind of SQL mixed with VBA. I just got this by finding it in google (I don't have the link handy now).
What the file does, is it will take 2 columns from a workbook called "Test.xls" and then take out 2 columns "Name" and "ID".
The only thing is, this is only a test and not the actual files I need to open. the files are always saved on the same folder, but the name is the day of the export of it. So when I export a file today, it will get 2014.09.10.xls. The sheet (only 1) will also get that name.
How could I change the below code that it will take that file based on today's date and read from the sheet with today's data?
VB: Sub sbADO() Dim sSQLQry As String Dim ReturnArray Dim Conn As New ADODB.Connection Dim mrs As New ADODB.Recordset Dim DBPath As String, sconnect As String 'DBPath = ThisWorkbook.FullName
I am trying to take the year from today's date then subtract away a date from a referenced date in a separate workbook. Then I want to put this result into an IF statement. For example if the result is between the number 1 and 4, display 1, if the result is between 5 and 9, display 2, etc. Right now, I'm simply trying to reference the separate workbook for the date and subtract that from today's date, but I'm stuck because I only get the date's serial number back.
1. Start w/ "RULE-Table" sheet, 2. Take note of "TODAY" date, 3. LOOKUP date in "RULE-table" 4. Locate Coordinates found in Col D of RULE-Table, 5. LOOKUP the data that resides in those Coordinates on the "PRODUCTION" sheet & COPY 6. PASTE data into "REPORT" tab C2 and E2.
Here's an example to visualize:
Code will do everything it needs to do within an Undisclosed OPEN file with several sheets. The reason the Workbook file name is undisclosed/undefined is because the file name will vary based on clients, so I don't want the code to be limited to look for a specific filename.
*The sheet names within this OPEN client file will always have the same names.
The sheet called: "RULE-Table" holds coordinates based upon "TODAY's" computer date. For example: If today is JAN 4, the desired coordinates to pull data from are "B5" and "D10" from the "PRODUCTION" sheet.
Since today is 1/4, its rules say go to B2 and D10 of the PRODUCTION tab and collect the data
"PRODUCTION" (data source) sheet (within the same open file) A.......B......C....D....E....F... Row1..Header..Hdr..Hdr..Hdr..Hdr. 2.......2................................. 3.......14............................... 4.......13............................... 5.......20............................... 6.......62.............................. 7....................76................. 8...................184................ 9...................375................ 10.................410................ 11.................525...............
Last, the collected data from those 2 coordinates should always get pasted onto the "REPORT" tab into C2 and E2 in this example.
"REPORT" (destination) sheet (within the same open file) A........B.........C.....D....E..... Row1..Header..Hdr..Hdr..Hdr.. 2...................20........410......
I have been working on this issue for some time, searches let me down paths to tell me of the color of the cell, but can't put all the pieces together. What I am trying to do, is upon Clicking Command Button 1 it will go row by row of column D (there are 2 headers so D3 would be the first fillable data) looking for dates that is past todays date, if past, it will color the cell red then copy it to the next available row in sheet2 then continue, date past due, color red, copy entire row to sheet 2 looping until the end is reached
I have a workbook that has worksheets that serve as data input pages for the user. I have control boxes created by the forms toolbar.
I created a splash screen that is to be launched when the file is opened. Instead, often the last sheet that the user was on when they last saved the file (usually but not always the worksheet called "Main Menu") is seen first.
I understand that not all the sheets can be hidden - that one must be unhidden.
So I created a sheet called "Background" that is a solid color with no gridelines.
Objective:
When the file is opened, I want the "Background" sheet to be seen first and then the splash screen to be initiated.
Now - when the user opens the file, the Main Menu worksheet is seen for a few seconds (or whatever the last sheet was on before it was last saved), then it disappears and the solid background screen is shown with the splash screen. When the splash screen ends, the "Background" sheet disappears.
Here is the code that I have in the workbook
Private Sub Workbook_Open() Dim wks As Worksheet On Error Resume Next For Each wks In ThisWorkbook If wks.Name "Background" Then wks.Visible = False End If Next wks End Sub
What has to be changed so that the first sheet that is seen upon opening the file is the "Background"; then the splash screen happens; then it returns to the Main Menu sheet?
I have found some excellent code that exports rows to individual sheets based on values in a column, and it works perfectly. I have found some code that deletes any rows that do not contain today's date:
VB:
Dim LR As Long, i As Long Application.ScreenUpdating = False LR = Range("O" & Rows.Count).End(xlUp).Row For i = LR To 1 Step -1 If Range("N" & i).Value < Date Then Rows(i).Delete 'N is column "Treatment Date" Next i Application.ScreenUpdating = True
But I'm having trouble adding this to the code I'm already using (that is working):
VB:
Sub Copy_To_Worksheets_2() 'Note: This macro use the function LastRow and SheetExists Dim My_Range As Range Dim FieldNum As Long Dim CalcMode As Long Dim ViewMode As Long Dim ws2 As Worksheet
[Code]...
I tried adding it after the code " ' delete columns (after exporting from Current Patients)" but I received the error "Compile error - Duplicate declaration in current scope" as it relates to Dim LR As Long.
I have attached my spreadsheet : Daily Treatment Summary.xlsm
I need a formula that will calculate the number of days from a date entered into cell A1 to today's date. Whether it's before or after todays date. Example:
If a1,a21,a41 have a value greater than 0, I wish to stamp cell b1,b21,b41 and so on with todays date, but without the stamped value changing/advancing tomorrow. At the moment cells b1,b21,b41 are copied down as follows. =if(a1>0,TODAY(),"") This works fine, but the date stamp of course changes tomorrow. I can not apply code to the whole b column as cells b2:b20, b22:40 etc have other non-date format data to which the code does not need to apply - the todays date value cell occurs every 20 cells.
how I can create a formula that would highlight the cell in a colour if the date was past todays date? This is what I'm doing - I have the expiry date of people's insurances. so e.g todays date is 8 th January, so if the insurance had expired 31.12.08, i would want the cell to be highlighted red. I think it may be an IF function but I cant remember.
I need to VBA code that will loop through the active sheet for all rows, column C2 through however many rows there are. Col C contains a date in the format: mm/dd/yyyy. I need the VBA to compare this date to today's date+30 days and if the date in C2, etc. is greater than today's date + 30 days, shade the row a particular background color (e.g., 3).
I'm looking to combine today's date and a string in the same cell. This is what i've come up with:
The problem is that this gives today's date in a numerical value rather than in "short date" form like I want. If i format the cell as a date it doesn't change anything.
Whatever the method, for what I'm doing it has to take place in on single cell.
Upon opening a spreadsheet, I would like a macro to highlight the cell which contains todays date. This will be selected from a range of dates which are already populated in column B. Is it possible to have a macro which can select the cell in column B which contains today's date? If possible, please could you include the code for doing this upon opening the spreadsheet. I'm not too confident about that either!
I've got the following function that check if each cell has a date greater than TODAY(). If result is true, it'll display "NO GO". Otherwise, it'll display "GO".
I would want to improve on it such that if any of the 'B5:F5' cell is empty, it'll display "Incomplete" instead of "No Go".
I've been using the following code and would like to add another IF that checks the value of a cell to see if it holds today's date.
Code: If Range("E" & CStr(LSearchRow)).Value "Closed" Then If Range("E" & CStr(LSearchRow)).Value "Closed w/o Customer Confirm" Then 'Select SR in Sheet to update Range("B" & CStr(LSearchRow)).Select
[Code] ......
I tried to modify it to...
Code: If Range("E" & CStr(LSearchRow)).Value "Closed" Then If Range("E" & CStr(LSearchRow)).Value "Closed w/o Customer Confirm" Then If Range("AK" & CStr(LSearchRow)).Value "=today()" Then 'Select SR in Sheet to update
[Code] ......
I've tried a couple of other things but no success
I’ve been searching the forum but am struggling to find exactly the information I need!
I’m trying to get a column of cells to update with the date that the cells contents change to “Y”. I had been using the formula =IF(I7="Y",TODAY(),"-") in cell J7 but this updates the date every day. I need this date to remain the same as when it’s first populated.
I’ve been trying to cut and paste text from existing posts into the Visual Basic code but am new to this so am not getting the results I need. I had tried:
Private Sub Worksheet_Change(ByVal Target As Excel.Range) 'will put date in column B when something is put in A If Target.Column = 9 Then Target.Offset(0, 1).Value = Date End If End Sub
But this caused all sorts of problems! I then tried messing around with:
Option Compare Text Private Sub Worksheet_Change(ByVal Target As Excel.Range) On Error GoTo enditall Application.EnableEvents = False If Target.Column = "I" Then If Target.Value = "Y" Then Excel.Range("J").Value = Date End If End If enditall: Application.EnableEvents = True End Sub
But this doesn’t work either. In fact, both these codes are probably riddled with errors as I’ve been trying to learn by trial and error!
I have made the macro that does as ,soon as i open the file, select today's date but only if date is in sheet5... sheet 5 is may so it works. Doing the same job for every sheet in the file.
This is a shot in the dark. I have a workbook with 12 sheets, one for each month of the year. Each month is divided into the different weeks of the month. For example sheet January is divided into:
Week 1: 1/1/12 through 1/7/12 Week 2: 1/8/12 through 1/14/12
and so on:
I would like my workbook to open on the cell containing the date range for that particular date.
For example, if I open the workbook on 1/10/12 I need the workbook to open on the cell range that contains Week 2: 1/8/12 through 1/14/12.
The following code is supposed to open a workbook, find txtVinput.value and put todays date (now()) in column C.
it doesn't generate any errors, but it doesn't add the date either. I'd post the file, but its just over the limit and I don't want to get into trouble (50K)
The whole prog is a userform that the operator enters a receipt number and it posts to another workbook, with the date. The operator also has the option to insert a date when the paperwork is returned. This is the part that is causing me trouble.
Sub InsertReturnInDatabase() Application. ScreenUpdating = False Application.EnableEvents = False