Forum Discussion
Rory123908
Jan 06, 2022Copper Contributor
Combining the date and time using VBA
Hi everyone. I have a problem. A VBA problem. I have a list of times every 30 seconds and I have a list of dates that correspond next to the times. I'm looking to create a function in VBA that allows...
HansVogelaar
Jan 06, 2022MVP
Try this:
Sub Combine()
Dim rangee As Range
Dim rangeee As Range
Dim rangeeee As Range
Dim m As Long
Set rangeee = GetCellFromUser("Please select the cell on the First row of data that represents time", "Selecting time cells (PWD DATA)", ActiveCell)
If rangeee Is Nothing Then
'user cancelled
Beep
Exit Sub
Else
'range was selected, now do something, like select all cells to the bottom of that range:
m = rangeee.End(xlDown).Row - rangeee.Row + 1
End If
Set rangeeee = GetCellFromUser("Please select the cell on the First row of data that represents date", "Selecting date cells (PWD DATA)", ActiveCell)
If rangeeee Is Nothing Then
'user cancelled
Beep
Exit Sub
End If
Set rangee = GetCellFromUser("Please select the row containing our variable headers", "Selecting headers (PWD DATA)", ActiveCell)
If rangee Is Nothing Then
'user cancelled
Beep
Exit Sub
Else
'range was selected, now do something, like select all cells to the bottom of the first range:
Set rangee = rangee.Resize(m)
End If
With rangee
.Formula = "=" & rangeeee.Address(False, False) & "+" & rangeee.Address(False, False)
.NumberFormat = "dd/mm/yyyy hh:mm:ss"
End With
End Sub