tejasdave
05-22-2012, 09:26 AM
Hello Guys,
I have a workbook with multiple worksheets.I have made a macro which does the cleanup of all the worksheets by performing below 3 steps:
1. Delete 1st Column in all sheets.
2. Delete all rows above cell containing "Header"
3. Add column "ID_Vs" in all sheets
4. Concatenate 2 values in the entire column.
I have the following code so far:
Sub LoopThroughSheets()
Dim ws As Worksheet
Dim lRowFound As Long
Dim lColFound As Long
Dim lColFound2 As Long
Dim lngLastRow As Long
For Each ws In ActiveWorkbook.Worksheets
On Error Resume Next 'Will continue if an error results
ws.Range("A:A").Delete
lRowFound = ws.UsedRange.Find("Header", LookIn:=xlValues).Row
ws.Rows("1:" & lRowFound - 1).Delete Shift:=xlUp
ws.Range("A:A").Insert
ws.Range("A1") = "ID_Vs"
lColFound = ws.UsedRange.Find("Header1", LookIn:=xlValues).Column
lColFound2 = ws.UsedRange.Find("Header2", LookIn:=xlValues).Column
ws.Cells(2, 1) = ws.Cells(2, lColFound) & ws.Cells(2, lColFound2)
Next ws
End Sub
The above code does everything but fails on one part.The problem is the code above only concatenates in cell A2 for each sheet and not the entire column.Filldown wont work as i have tried it.
Any help would be grateful.
Regards,
Tejas
I have a workbook with multiple worksheets.I have made a macro which does the cleanup of all the worksheets by performing below 3 steps:
1. Delete 1st Column in all sheets.
2. Delete all rows above cell containing "Header"
3. Add column "ID_Vs" in all sheets
4. Concatenate 2 values in the entire column.
I have the following code so far:
Sub LoopThroughSheets()
Dim ws As Worksheet
Dim lRowFound As Long
Dim lColFound As Long
Dim lColFound2 As Long
Dim lngLastRow As Long
For Each ws In ActiveWorkbook.Worksheets
On Error Resume Next 'Will continue if an error results
ws.Range("A:A").Delete
lRowFound = ws.UsedRange.Find("Header", LookIn:=xlValues).Row
ws.Rows("1:" & lRowFound - 1).Delete Shift:=xlUp
ws.Range("A:A").Insert
ws.Range("A1") = "ID_Vs"
lColFound = ws.UsedRange.Find("Header1", LookIn:=xlValues).Column
lColFound2 = ws.UsedRange.Find("Header2", LookIn:=xlValues).Column
ws.Cells(2, 1) = ws.Cells(2, lColFound) & ws.Cells(2, lColFound2)
Next ws
End Sub
The above code does everything but fails on one part.The problem is the code above only concatenates in cell A2 for each sheet and not the entire column.Filldown wont work as i have tried it.
Any help would be grateful.
Regards,
Tejas