Excel Macro

N

Neal

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
 
B

Bernie Deitrick

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top