ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   macro code required (https://www.excelbanter.com/excel-worksheet-functions/185322-macro-code-required.html)

muddan madhu

macro code required
 
Hi,

I have a macro to calculate the time ...
Col A - Start time
Col B - End Time


similarly, I have Col C , Col D , Col E , Col F......... ( Start Time
& End Time)


I have Created Buttons ( in top row Button 1, Button 2 , Button 3 )


Button 1 - for Col A , B
Button 2 - for Col C, D
Button 3 - for Col E, F


If user click that buttton it gives the system time as 00:06:53 in A5
(hh:mm:ss) and again
if user click that button it will gives the system 00:06:55 in B5 &
moves to A6 cell.
if user click that button it gives the time in A6 and Moves to B6.
similarly it moves down as and when user clicks..


What i need is - If the user clicks button 1, the activecell should
be
A5 and it moves on.
If user click button 3, the activecell should be E5.


Please Check code and test it and advice if you there is better
option
rather than this ?


Here is my code :


Sub macro1()


ActiveCell.Select
If ActiveCell = "" Then
ActiveCell.FormulaR1C1 = "=now()-Today()"
Selection.Copy
'ActiveCell.Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Else
If ActiveCell < "" Then
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "=now()-Today()"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False


If ActiveCell 0 Then
ActiveCell.Offset(1, -1).Select


End If
End If
End If
End Sub



Bernie Deitrick

macro code required
 
See my reply in .Programming

--
HTH,
Bernie
MS Excel MVP


"muddan madhu" wrote in message
...
Hi,

I have a macro to calculate the time ...
Col A - Start time
Col B - End Time


similarly, I have Col C , Col D , Col E , Col F......... ( Start Time
& End Time)


I have Created Buttons ( in top row Button 1, Button 2 , Button 3 )


Button 1 - for Col A , B
Button 2 - for Col C, D
Button 3 - for Col E, F


If user click that buttton it gives the system time as 00:06:53 in A5
(hh:mm:ss) and again
if user click that button it will gives the system 00:06:55 in B5 &
moves to A6 cell.
if user click that button it gives the time in A6 and Moves to B6.
similarly it moves down as and when user clicks..


What i need is - If the user clicks button 1, the activecell should
be
A5 and it moves on.
If user click button 3, the activecell should be E5.


Please Check code and test it and advice if you there is better
option
rather than this ?


Here is my code :


Sub macro1()


ActiveCell.Select
If ActiveCell = "" Then
ActiveCell.FormulaR1C1 = "=now()-Today()"
Selection.Copy
'ActiveCell.Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Else
If ActiveCell < "" Then
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "=now()-Today()"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False


If ActiveCell 0 Then
ActiveCell.Offset(1, -1).Select


End If
End If
End If
End Sub





muddan madhu

macro code required
 
Bernie,

Thank u very much, it works great.


I need small help, Please help me.


I need to learn advance coding in Excel VBA. Can u guide me ?




On Apr 28, 7:14*pm, "Bernie Deitrick" <deitbe @ consumer dot org
wrote:
See my reply in .Programming

--
HTH,
Bernie
MS Excel MVP

"muddan madhu" wrote in message

...



Hi,


I have a macro to calculate the time ...
Col A - Start time
Col B - End Time


similarly, I have Col C , Col D , Col E , Col F......... ( Start Time
& End Time)


I have Created Buttons ( in top row Button 1, Button 2 , Button 3 )


Button 1 - for Col A , B
Button 2 - for Col C, D
Button 3 - for Col E, F


If user click that buttton it gives the system time as 00:06:53 in A5
(hh:mm:ss) and again
if user click that button it will gives the system 00:06:55 in B5 &
moves to A6 cell.
if user click that button it gives the time in A6 and Moves to B6.
similarly it moves down as and when user clicks..


What i need is - If the user clicks button 1, the activecell should
be
A5 and it moves on.
If user click button 3, the activecell should be E5.


Please Check code and test it and advice if you there is better
option
rather than this ?


Here is my code :


Sub macro1()


ActiveCell.Select
If ActiveCell = "" Then
ActiveCell.FormulaR1C1 = "=now()-Today()"
Selection.Copy
'ActiveCell.Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Else
If ActiveCell < "" Then
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "=now()-Today()"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False


If ActiveCell 0 Then
ActiveCell.Offset(1, -1).Select


End If
End If
End If
End Sub- Hide quoted text -


- Show quoted text -




All times are GMT +1. The time now is 07:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com