Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
make cell active in beginning of macro
I am running the following code which works great for inserting a date into a
cell with a calendar, but it only works great if they are in the right active cell when they click the macro. I need to reduce errors by making the active cell b1 when they start the macro, do that it will check the date in that cell, and return the date in that cell. I'm lost., any help would be appreciated. Thanks Private Sub UserForm_Initialize() If IsDate(ActiveCell.Value) Then Calendar1.Value = DateValue(ActiveCell.Value) Else Calendar1.Value = Date Range("B1").Value = Date End If End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
make cell active in beginning of macro
Pam
Private Sub UserForm_Initialize() Range("b1").select If IsDate(ActiveCell.Value) Then Calendar1.Value = DateValue(ActiveCell.Value) Else Calendar1.Value = Date Range("B1").Value = Date End If Best N10 End Sub "Pam" wrote in message ... I am running the following code which works great for inserting a date into a cell with a calendar, but it only works great if they are in the right active cell when they click the macro. I need to reduce errors by making the active cell b1 when they start the macro, do that it will check the date in that cell, and return the date in that cell. I'm lost., any help would be appreciated. Thanks Private Sub UserForm_Initialize() If IsDate(ActiveCell.Value) Then Calendar1.Value = DateValue(ActiveCell.Value) Else Calendar1.Value = Date Range("B1").Value = Date End If End Sub |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
make cell active in beginning of macro
Private Sub UserForm_Initialize()
If IsDate(Range("B1").Value) Then Calendar1.Value = DateValue(Range("B1").Value) Else Calendar1.Value = Date Range("B1").Value = Date End If End Sub "Pam" wrote: I am running the following code which works great for inserting a date into a cell with a calendar, but it only works great if they are in the right active cell when they click the macro. I need to reduce errors by making the active cell b1 when they start the macro, do that it will check the date in that cell, and return the date in that cell. I'm lost., any help would be appreciated. Thanks Private Sub UserForm_Initialize() If IsDate(ActiveCell.Value) Then Calendar1.Value = DateValue(ActiveCell.Value) Else Calendar1.Value = Date Range("B1").Value = Date End If End Sub |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
make cell active in beginning of macro
Thank you, I knew it was simple
"N10" wrote: Pam Private Sub UserForm_Initialize() Range("b1").select If IsDate(ActiveCell.Value) Then Calendar1.Value = DateValue(ActiveCell.Value) Else Calendar1.Value = Date Range("B1").Value = Date End If Best N10 End Sub "Pam" wrote in message ... I am running the following code which works great for inserting a date into a cell with a calendar, but it only works great if they are in the right active cell when they click the macro. I need to reduce errors by making the active cell b1 when they start the macro, do that it will check the date in that cell, and return the date in that cell. I'm lost., any help would be appreciated. Thanks Private Sub UserForm_Initialize() If IsDate(ActiveCell.Value) Then Calendar1.Value = DateValue(ActiveCell.Value) Else Calendar1.Value = Date Range("B1").Value = Date End If End Sub |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
make cell active in beginning of macro
Joel,
When I tried this it put the result in the cell I was in, although it seems to be comparing the original cell? "Joel" wrote: Private Sub UserForm_Initialize() If IsDate(Range("B1").Value) Then Calendar1.Value = DateValue(Range("B1").Value) Else Calendar1.Value = Date Range("B1").Value = Date End If End Sub "Pam" wrote: I am running the following code which works great for inserting a date into a cell with a calendar, but it only works great if they are in the right active cell when they click the macro. I need to reduce errors by making the active cell b1 when they start the macro, do that it will check the date in that cell, and return the date in that cell. I'm lost., any help would be appreciated. Thanks Private Sub UserForm_Initialize() If IsDate(ActiveCell.Value) Then Calendar1.Value = DateValue(ActiveCell.Value) Else Calendar1.Value = Date Range("B1").Value = Date End If End Sub |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
make cell active in beginning of macro
Pam: The code you posted is only the initialize function when the userform is
opened. Check to see if the active cell gets changed before you enter anything into the userform. If the active cell doesn't get changed during the initialization then there is other code that is writing to the active cell that you didn't post. The code you posted should only change two items. Range "B1" and the initial vbalue in Calandar1.value which I assume is some box on the form (textbox, listbox, combobox). "Pam" wrote: Joel, When I tried this it put the result in the cell I was in, although it seems to be comparing the original cell? "Joel" wrote: Private Sub UserForm_Initialize() If IsDate(Range("B1").Value) Then Calendar1.Value = DateValue(Range("B1").Value) Else Calendar1.Value = Date Range("B1").Value = Date End If End Sub "Pam" wrote: I am running the following code which works great for inserting a date into a cell with a calendar, but it only works great if they are in the right active cell when they click the macro. I need to reduce errors by making the active cell b1 when they start the macro, do that it will check the date in that cell, and return the date in that cell. I'm lost., any help would be appreciated. Thanks Private Sub UserForm_Initialize() If IsDate(ActiveCell.Value) Then Calendar1.Value = DateValue(ActiveCell.Value) Else Calendar1.Value = Date Range("B1").Value = Date End If End Sub |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
make cell active in beginning of macro
Okay, the B1 is the cell that I want it to check to see if there's a date,
and change that if there is not a date, does that make sense? If there is a date, I want it to leave it alone, if there is not, I want it to default to today's date, I probably have the code wrong, but this will work for now. Thanks "Joel" wrote: Pam: The code you posted is only the initialize function when the userform is opened. Check to see if the active cell gets changed before you enter anything into the userform. If the active cell doesn't get changed during the initialization then there is other code that is writing to the active cell that you didn't post. The code you posted should only change two items. Range "B1" and the initial vbalue in Calandar1.value which I assume is some box on the form (textbox, listbox, combobox). "Pam" wrote: Joel, When I tried this it put the result in the cell I was in, although it seems to be comparing the original cell? "Joel" wrote: Private Sub UserForm_Initialize() If IsDate(Range("B1").Value) Then Calendar1.Value = DateValue(Range("B1").Value) Else Calendar1.Value = Date Range("B1").Value = Date End If End Sub "Pam" wrote: I am running the following code which works great for inserting a date into a cell with a calendar, but it only works great if they are in the right active cell when they click the macro. I need to reduce errors by making the active cell b1 when they start the macro, do that it will check the date in that cell, and return the date in that cell. I'm lost., any help would be appreciated. Thanks Private Sub UserForm_Initialize() If IsDate(ActiveCell.Value) Then Calendar1.Value = DateValue(ActiveCell.Value) Else Calendar1.Value = Date Range("B1").Value = Date End If End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
macro to find cell content in sheets and make sheet active | Excel Discussion (Misc queries) | |||
use current cell address as beginning of macro | Excel Discussion (Misc queries) | |||
Make the next cell active | Excel Programming | |||
Make a Word event macro fire in active document | Excel Programming | |||
Make a particular cell the active one | Excel Programming |