Hello to All,
Thanks in advance i am new to Macros it would be really helpful if some one will help me here.
I have a macro code which copies the data from multiple excel files in a folder and copies it to a single excel file it works fine.But now the problem is some of those excel files have hidden column for example column A and B are hidden and these files are password protected can any one help me modify my macro to solve the problem of coping
All these excel files with hidden columns
And un protecting them from the password.
Here is my code please feel free to modify this.
Sub BigMerge()
Dim DestCell As Range
Dim DataColumn As Variant
Dim NumberOfColumns As Variant
Dim WB As Workbook
Dim DestWB As Workbook
Dim ws As Worksheet
Dim FileNames As Variant
Dim N As Long
Dim r As Range
Dim StartRow As Long
Dim LastRow As Long
Dim RowNdx As Long
' Create a new workbook for the consolidated
' data.
Set DestWB = Workbooks.Add
' OR use the ActiveWorkbook:
'Set DestWB = ActiveWorkbook
' OR use an open workbook
'Set DestWB = Workbooks("Book1.xls")
' DestCell is the first cell where the consolidated
' data will be written.
Set DestCell = DestWB.Worksheets(1).Range("A1")
' DataColumn is the column on the worksheets to be
' consolidated where the actual data is. Data will
' be copied from this column.
DataColumn = "A"
' NumberOfColumns is the number of columns on each
' worksheet to be consolidated from which data will
' be copied. E.g., if your data is in range A1:J100,
' NumberOfColumns would be 10.
NumberOfColumns = 12
' StartRow is the row on the worksheets to be consolidated
' where the data starts. If your worksheet have heading/summary
' rows at the top, set this value to the row number where
' the actual data starts.
StartRow = 4
' Get the workbooks to consolidate
FileNames = Application.GetOpenFilename( _
filefilter:="Excel Files (*.xls*),*.xls*", _
Title:="Select the workbooks to merge.", MultiSelect:=True)
If IsArray(FileNames) = False Then
If FileNames = False Then
' User cancelled open dialog. get out.
Exit Sub
End If
End If
' Loop through all the selected files.
For N = LBound(FileNames) To UBound(FileNames)
' Open the workbook
Set WB = Workbooks.Open(FileName:=FileNames(N), ReadOnly:=True)
' Loop through all the worksheets in the workbook
For Each ws In WB.Worksheets
With ws
' Test if worksheet has content. It must have
' at least two cells with content. Otherwise,
' it is assumed to be empty and will not be
' processed.
If ws.UsedRange.Cells.Count > 1 Then
' Get the last row in DataColumn
' that has data.
LastRow = .Cells(.Rows.Count, DataColumn). _
End(xlUp).Row
' Loop through the rows, statring at StartRow
' and going down to LastRow.
For RowNdx = StartRow To LastRow
' Copy the cells on row RowNdx
' starting in DataColumn for NumberOfColumns'
' columns wide. Data is copied to
' DestCell.
.Cells(RowNdx, DataColumn). _
Resize(1, NumberOfColumns).Copy _
Destination:=DestCell
' Move the DestCell down one row.
Set DestCell = DestCell(2, 1)
Next RowNdx
End If
End With
Next ws
' close the workbook.
WB.Close savechanges:=False
Next N
End Sub
Above code works fine when excel sheets do not have password protection with hidden columns.
Bookmarks