Excel Macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
Back
Top