#1   Report Post  
Neal
 
Posts: n/a
Default Excel Macro

I have never built any macros before so I did a little reading on how to do
it. Im trying to combine a date cell with a time cell, I can get the macro to
work but it only copies the cell that the macro was created on to every other
cell. I use the relative reference button but it still does the same thing!
Is there something that Im not doing. I have a couple hundred cells to merge
together so I thought I could just make a macro? Any help would be greatly
appreciated.

Thanks, Neal
  #2   Report Post  
Bernie Deitrick
 
Posts: n/a
Default

Neal,

If your cells need to be selected, you could do something like the first
macro below, which prompts the user to select the time cells and the date
cells.

If your cells are anchored by a set cell, then you could do something like
the second macro below, which selects the time cells and the date cells
based on the top cell. In either, change the formatting to the style you
prefer.

HTH,
Bernie
MS Excel MVP

Sub Macro1()
Dim TimeCells As Range
Dim DateCells As Range

Set TimeCells = Application.InputBox("Select the Time cells", , , , , , , 8)
Set DateCells = Application.InputBox("Select the Date cells", , , , , , , 8)

TimeCells.Copy
DateCells.PasteSpecial Operation:=xlAdd
DateCells.NumberFormat = "m/d/yyyy hh:mm:ss AM/PM"
DateCells.EntireColumn.AutoFit
End Sub

Sub Macro2()
Dim TimeCells As Range
Dim DateCells As Range

Set TimeCells = Range("B1")
Set DateCells = Range("C1")

Set TimeCells = Range(TimeCells, TimeCells.End(xlDown))
Set DateCells = Range(DateCells, DateCells.End(xlDown))

TimeCells.Copy
DateCells.PasteSpecial Operation:=xlAdd
DateCells.NumberFormat = "m/d/yyyy hh:mm:ss AM/PM"
DateCells.EntireColumn.AutoFit
End Sub




"Neal" wrote in message
...
I have never built any macros before so I did a little reading on how to

do
it. Im trying to combine a date cell with a time cell, I can get the macro

to
work but it only copies the cell that the macro was created on to every

other
cell. I use the relative reference button but it still does the same

thing!
Is there something that Im not doing. I have a couple hundred cells to

merge
together so I thought I could just make a macro? Any help would be greatly
appreciated.

Thanks, Neal



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving Excel using Macro mrbalaje Excel Discussion (Misc queries) 4 April 20th 05 02:32 PM
How do I find a Macro in Excel when I don't know its name? LLEECEE Excel Discussion (Misc queries) 2 March 31st 05 10:28 PM
How can I edit cell contents with a macro in Excel? Mind the gaps! Excel Discussion (Misc queries) 2 March 23rd 05 08:51 PM
Problem Editing Macro in Shared Excel File [email protected] Excel Discussion (Misc queries) 1 March 19th 05 06:43 PM
Open Access Database under and Excel window using a Macro BMSpell Excel Worksheet Functions 1 January 8th 05 05:32 PM


All times are GMT +1. The time now is 06:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"