Forum Discussion
rijuthomas
Jul 22, 2019Copper Contributor
Need help in macros
i have a excel which i have attached to this post, where in raw sheet is the raw data in which i need to insert a column in between A and B and copy the heading of the data against the date, final copy how i want i have attached in the other sheet.
3 Replies
- KodipadyIron Contributor
I may be missing something, your attached file July DRAFT.XLS has only one sheet called "Sheet1". Column B has a header called "DOCUMENT DATE". Is that the new column you would like to insert? If yes, how do you derive this column value?
- rijuthomasCopper Contributor
Kodipadysorry i think wrong file uploaded, have uploaded correct file
let me know any doubts
<Admin Removed File Attachment for Privacy Reasons >>
Here you go:
Sub InsertColumn() Dim wsh As Worksheet Dim ref As String Dim r As Long Dim m As Long Dim v As Variant Application.ScreenUpdating = False Set wsh = ActiveSheet ' Worksheets("raw sheet") wsh.Range("B1").EntireColumn.Insert m = wsh.Range("C" & wsh.Rows.Count).End(xlUp).Row For r = 3 To m v = wsh.Range("C" & r).Value If IsNumeric(v) Or IsDate(v) Then wsh.Range("B" & r).Value = ref Else ref = v End If Next r wsh.UsedRange.EntireColumn.AutoFit Application.ScreenUpdating = True End Sub