Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add and Delete Excel Columns VBScript

Status
Not open for further replies.

unique12u

Technical User
Jul 25, 2004
14
0
0
US
I have an excel sheet where column C is a date, Column D is a time and Column E is blank. Number of rows can vary.

I need code to tell it to add column C and D together into column E and then format column E as mm/dd/yyyy hh:mm:ss
and then delete column C and D.

Any help out there?

Thanks
Nique
 
This will get r done!




rowcounter = ActiveSheet.UsedRange.Rows.Count
For a = 2 To rowcounter
daterange = ("c" & a & ":c" & a)
timerange = ("d" & a & ":d" & a)
newcellrange = ("e" & a & ":e" & a)
Range(daterange).Select
datecell = ActiveCell.Text
Range(timerange).Select
timecell = ActiveCell.Text
newcellvalue = datecell & " " & timecell
Range(newcellrange).Select
ActiveCell.FormulaR1C1 = newcellvalue

Next
Columns("C:D").Select
Selection.Delete Shift:=xlToLeft
 
How do I get it reformatted into my correct format?

mm/dd/yyyy hh:mm:ss

If I do the concatenation you suggest it will be m/d/yy hh:mm

 
Columns("c:c").Select
Selection.NumberFormat = "mm/dd/yyyy"
Columns("d:d").Select
Selection.NumberFormat = "[$-409]h:mm:ss AM/PM;@"
rowcounter = ActiveSheet.UsedRange.Rows.Count
For a = 2 To rowcounter
daterange = ("c" & a & ":c" & a)
timerange = ("d" & a & ":d" & a)
newcellrange = ("e" & a & ":e" & a)
Range(daterange).Select
datecell = ActiveCell.Text
Range(timerange).Select
timecell = ActiveCell.Text
newcellvalue = datecell & " " & timecell
Range(newcellrange).Select
ActiveCell.FormulaR1C1 = newcellvalue

Next
Columns("C:D").Select
Selection.Delete Shift:=xlToLeft
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top