|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: |
Option Explicit
Sub OpenWorkbooks()
'------
Dim Book_Name As range ' List of available books
Dim Sheet_Name As range ' List of available sheets
Dim dLastRow As Long
Dim oLastRow As Long
Dim sLastRow As Long
Dim DestinationSheet As Worksheet
Dim SourceSheet As Worksheet
Dim WorkBookList As range
Dim WorkSheetList As range
Dim WorkbookPath As String
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.EnableEvents = False
End With
'set source and destination sheet
Set DestinationSheet = Sheets("Raw Data")
Set SourceSheet = Sheets("Parameters")
With SourceSheet
' Path of the workbooks
WorkbookPath = range("C4")
' List of available workbooks
Set WorkBookList = range("D5:D16")
' List of available worksheets
Set WorkSheetList = range("F5:F16")
End With
With DestinationSheet
' Delete any exsisting data and paste in row after heading
dLastRow = range("A" & Rows.Count) + 2
'Save
oLastRow = dLastRow
' for each book name in the workbook list
For Each Book_Name In WorkBookList
' If cell next to it has a Y or y in it then open workbook, if anything else raise error
If UCase(Book_Name.Offset(0, 1)) = "Y" Then
Workbooks.Open WorkbookPath & Book_Name
' for each sheet name in the sheetname list
For Each Sheet_Name In WorkSheetList
'------------------------------------------------------------------------------------------
' If cell next to it has a Y or y in it then use worksheet, if anything else dont
If UCase(Sheet_Name.Offset(0, 1)) = "Y" Then
'Where from
Set SourceSheet = ActiveWorkbook.Sheets(Sheet_Name.Value)
'Get last row of data
sLastRow = SourceSheet.range("A" & Rows.Count).End(xlUp).Row
'If data
If sLastRow > 1 Then
'Copy
SourceSheet.range("A3:E" & sLastRow).Copy .range("B" & dLastRow)
'Get new last row of destination
dLastRow = .range("B" & Rows.Count).End(xlUp).Row + 1
'Put workbook name into first column
.range("A" & oLastRow & ":A" & dLastRow - 1) = Book_Name.Value
'Save
oLastRow = dLastRow
'---------------------------------------------------------------------------------------------
End If
End If
'next sheet in list
Next Sheet_Name
'close workbook
ActiveWorkbook.Close True
End If
'Next workbook
Next Book_Name
End With
'------
' Message to user that import is complete
MsgBox ("Data refresh complete"), vbInformation, "Done!"
'------
' set all to nothing
Set Book_Name = Nothing
Set Sheet_Name = Nothing
Set DestinationSheet = Nothing
Set SourceSheet = Nothing
Set WorkBookList = Nothing
Set WorkSheetList = Nothing
'------
' turn functions back on
With Application
.ScreenUpdating = True
.DisplayAlerts = True
.EnableEvents = True
End With
End Sub
|
Advertisement
| Hall of Fame |