I need to consolidate multiple columns- macro
Closed
jonnynomates
Posts
1
Registration date
Monday April 5, 2010
Status
Member
Last seen
April 5, 2010
-
Apr 5, 2010 at 09:35 AM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Apr 5, 2010 at 05:37 PM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Apr 5, 2010 at 05:37 PM
Related:
- I need to consolidate multiple columns- macro
- How to delete multiple files on mac - Guide
- How to make multiple selections in photoshop - Guide
- Allow multiple downloads chrome - Guide
- Display two columns in data validation list but return only one - Guide
- Spell number in excel without macro - Guide
1 response
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Apr 5, 2010 at 05:37 PM
Apr 5, 2010 at 05:37 PM
Assumptions
1. The consolidated column will not exceed the excel row limitation
1. The consolidated column will not exceed the excel row limitation
Sub consolidate() Dim lMaxRows As Long Dim lRowBeanCounter As Long Dim Sheet As Variant Dim sLookForColumn As String Dim iTargetColumn As Integer Dim iMaxCols As Integer Dim sRecSheet As String sLookForColumn = "Record Date Position" sRecSheet = "Reconciliation" On Error Resume Next Sheets(sRecSheet).Delete On Error GoTo 0 Sheets.Add ActiveSheet.Name = sRecSheet Cells(1, "A") = sLookForColumn Cells(1, "B") = "From Sheet" lRowBeanCounter = 1 For Each Sheet In Sheets If Sheet.Name = sRecSheet Then GoTo Next_Sheet Sheet.Select iTargetColumn = 0 On Error Resume Next iTargetColumn = Application.WorksheetFunction.Match(sLookForColumn, Range(Cells(1, "A"), Cells(1, Columns.Count)), 0) On Error GoTo 0 If (iTargetColumn > 0) Then lMaxRows = Cells(Rows.Count, iTargetColumn).End(xlUp).Row If (lMaxRows > 1) Then lRowBeanCounter = lRowBeanCounter + 1 Range(Cells(2, iTargetColumn), Cells(lMaxRows, iTargetColumn)).Select Selection.Copy Sheets(sRecSheet).Select Cells(lRowBeanCounter, "A").Select ActiveSheet.PasteSpecial xlValue lMaxRows = Cells(Rows.Count, "A").End(xlUp).Row Range(Cells(lRowBeanCounter, "B"), Cells((lMaxRows), "B")).Value = Sheet.Name lRowBeanCounter = lMaxRows End If End If Next_Sheet: Next Sheet End Sub