Excel VB Macro
Solved/Closed
b_85
Posts
4
Registration date
Thursday May 19, 2011
Status
Member
Last seen
May 23, 2011
-
May 19, 2011 at 09:32 AM
b_85 Posts 4 Registration date Thursday May 19, 2011 Status Member Last seen May 23, 2011 - May 20, 2011 at 06:48 AM
b_85 Posts 4 Registration date Thursday May 19, 2011 Status Member Last seen May 23, 2011 - May 20, 2011 at 06:48 AM
Related:
- Excel VB Macro
- Spell number in excel without macro - Guide
- Excel mod apk for pc - Download - Spreadsheets
- Excel marksheet - Guide
- Macros in excel download free - Download - Spreadsheets
- Kernel for excel - Download - Backup and recovery
4 responses
venkat1926
Posts
1863
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
811
May 20, 2011 at 06:15 AM
May 20, 2011 at 06:15 AM
try this modification (if archives sheet is some where in between one column may be blank-delete that blank column )
Sub test() Dim ws As Worksheet Dim sString As String Dim sCell As Variant Dim cfind As Range Dim j As Integer 'cfind = "ID" For Each ws In Worksheets If ws.Name = "archive" Then GoTo nextws ws.Activate j = ActiveSheet.Index 'MsgBox j On Error Resume Next Set cfind = Cells.Find(what:="ID", lookat:=xlWhole) If Not cfind Is Nothing Then cfind.EntireColumn.Copy 'Worksheets("archive").Cells(1, Columns.Count).End(xlToLeft).Offset(0, 1).PasteSpecial Worksheets("archive").Range("A1").Offset(0, j - 1).PasteSpecial ''If ActiveCell.Value = sfind Then ''Range(Selection, Selection.End(xlDown)).Select ''Selection.Copy ''ActiveWindow.ScrollWorkbookTabs Sheets:=2 ''Sheets("Sheet2").Select ''ActiveSheet.Paste End If nextws: Next ws End Sub
venkat1926
Posts
1863
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
811
May 19, 2011 at 08:41 PM
May 19, 2011 at 08:41 PM
1. do not copy to shee2. but insert a new worksheet and call it "archive".(it can be any name in that case modify the macro)
the columns called ID in the sheets other than "archive" will be copied in the columns in "archive" from left to right.
in archives column A will be blank you can delete that column
modification of your macro is:
the columns called ID in the sheets other than "archive" will be copied in the columns in "archive" from left to right.
in archives column A will be blank you can delete that column
modification of your macro is:
Sub test() Dim ws As Worksheet Dim sString As String Dim sCell As Variant Dim cfind As Range 'cfind = "ID" For Each ws In Worksheets If ws.Name = "archive" Then GoTo nextws ws.Activate On Error Resume Next Set cfind = Cells.Find(what:="ID", lookat:=xlWhole) If Not cfind Is Nothing Then cfind.EntireColumn.Copy Worksheets("archive").Cells(1, Columns.Count).End(xlToLeft).Offset(0, 1).PasteSpecial ''If ActiveCell.Value = sfind Then ''Range(Selection, Selection.End(xlDown)).Select ''Selection.Copy ''ActiveWindow.ScrollWorkbookTabs Sheets:=2 ''Sheets("Sheet2").Select ''ActiveSheet.Paste End If nextws: Next ws End Sub
b_85
Posts
4
Registration date
Thursday May 19, 2011
Status
Member
Last seen
May 23, 2011
May 20, 2011 at 04:23 AM
May 20, 2011 at 04:23 AM
Hi thanks for your help, this works perfectly expect for the fact that the "ID" may not always be in row 1.
I have noticed that if the header is not in row 1 and say in row 2 then it does not copy that column over. Any suggestions?
Thank you very much for your help.
I have noticed that if the header is not in row 1 and say in row 2 then it does not copy that column over. Any suggestions?
Thank you very much for your help.
b_85
Posts
4
Registration date
Thursday May 19, 2011
Status
Member
Last seen
May 23, 2011
May 20, 2011 at 06:48 AM
May 20, 2011 at 06:48 AM
Thanks so much, it works perfectly now