I have an Excel with two sheets named "Complaints" and "Add Row".
I am using the Add Row sheet to add a row (after the last row with values) to a table named ComplaintsTable in Complaints sheet and I am using a macro paired with a command button to do this.
My code looks like this:
Private Sub CommandButton1_Click()
Dim LastRow As Long, ws As Worksheet, ws1 As Worksheet, newRow As ListRow
Set ws = Sheets("Complaints")
Set ws1 = Sheets("Add Row")
Set tbl = ws.ListObjects("ComplaintsTable")
Set newRow = tbl.ListRows.Add
With newRow
.Range(2) = ws1.Range("C1").Value 'Complaint Yes/No
.Range(12) = ws1.Range("C6").Value 'PCE Yes/No
End With
newRow.Range(4) = ws1.Range("C4").Value 'Subject
newRow.Range(21) = ws1.Range("C5").Value 'Entered Date
'To add Hyperlink
If (ws1.Range("C1").Value = "Yes") Then
ws.Hyperlinks.Add Anchor:=tbl.newRow.Range(3), _
Address:=ws1.Range("F3").Value, _
ScreenTip:="Open Complaint in EtQ", _
TextToDisplay:=Worksheets("Add Row").Range("F2").Value
End If
If (ws1.Range("C6").Value = "Yes") Then
'To add hyperlink and PCE Number
ws.Hyperlinks.Add Anchor:=tbl.newRow.Range(13), _
Address:=ws1.Range("F8").Value, _
ScreenTip:="Open PCE in EtQ", _
TextToDisplay:=ws1.Range("F7").Value
End If
End Sub
Somehow when I clicked the command button to add values it doesn't add anything! Where am I going wrong?
Here is your refactored, cleaned up code with screenshots. As mentioned by both #Ibo and myself, The problem most likely lies in the fact that you've declared and set newRow as a range but then used it as a property of your table which is impossible.
Option Explicit
Private Sub CommandButton1_Click()
Dim wsComplaints As Worksheet, wsAddRow As Worksheet
Dim tblComplaints As ListObject
Dim lngRows As Long
With ThisWorkbook
Set wsComplaints = .Worksheets("Complaints")
Set wsAddRow = .Worksheets("Add Row")
End With
Set tblComplaints = wsComplaints.ListObjects("ComplaintsTable")
tblComplaints.ListRows.Add
lngRows = tblComplaints.ListRows.Count
With tblComplaints
.DataBodyRange(lngRows, 2) = wsAddRow.Cells(1, 3)
.DataBodyRange(lngRows, 4) = wsAddRow.Cells(4, 3)
.DataBodyRange(lngRows, 12) = wsAddRow.Cells(6, 3)
.DataBodyRange(lngRows, 21) = wsAddRow.Cells(5, 3)
End With
If wsAddRow.Cells(1, 3) = "Yes" Then
tblComplaints.DataBodyRange(lngRows, 3).Hyperlinks.Add _
Anchor:=tblComplaints.DataBodyRange(lngRows, 3), _
Address:=CStr(wsAddRow.Cells(3, 6)), _
ScreenTip:="Open complaint in EtQ", _
TextToDisplay:=CStr(wsAddRow.Cells(2, 6))
End If
If wsAddRow.Cells(6, 3) = "Yes" Then
tblComplaints.DataBodyRange.Hyperlinks.Add _
Anchor:=tblComplaints.DataBodyRange(lngRows, 13), _
Address:=CStr(wsAddRow.Cells(8, 6)), _
ScreenTip:="Open PCE in EtQ", _
TextToDisplay:=CStr(wsAddRow.Cells(7, 6))
End If
End Sub
Screenshots of the solution.
If you click the button and nothing, not even an error of any sort, happens there may be several issues.
To start of with, as mentioned by #Carol, the newRow is not supposed to be qualified by tbl as newRow is not a property or method of tbl
Possibility 1:
You've added a Form Control button to your sheet which you are unable to assign a Private Sub CommandButton1_Click() because, well, it is private and can only be used within the code module it is placed in, it cannot be referenced outside of it.
Possibility 2:
You've added an ActiveX CommandButton, wrote the Private Sub CommandButton1_Click() but then changed the name of the button. In that case, change the CommandButton1 to whatever you've named your button.
Possibility 3:
You've encountered an error, hit debug and the code is paused. As long as the code is paused, no new event will fire and thus your button will appear to do nothing. This is recognized by a line of your code highlighted in yellow. You need to fix the line which caused the error and resume your code by hitting F5 or hitting the stop icon usually located somewhere near the top of your VBA window.
Your text to display must be a zero-length string and that is it is failing to create the hyperlink.
define the text to display like this before to make sure this line is the problem:
myStr=Worksheets("Add Row").Range("F2").Value
Try to define variables and range objects before adding the hyperlink, instead of using the .value etc put them in a string variable and make sure all of them have a valid value. If you try this, it should work, otherwise follow the above instruction and you will find where the problem is:
Replace this block and if it worked, change the other block in the same way:
If (ws1.Range("C1").Value = "Yes") Then
ws.Hyperlinks.Add Anchor:=tbl.newRow.Range(3), _
Address:=ws1.Range("F3").Value, _
ScreenTip:="Open Complaint in EtQ", _
TextToDisplay:=IIf(mystr <> "", mystr, "Click Here")
End If
I have changed the code as follows and it is working perfectly fine without any errors.
Private Sub AddRow_Click()
Dim LastRow As Long, ws As Worksheet, ws1 As Worksheet
Dim newRow As ListRow ', tbl As ListObjects
Dim cmpNo As String, pceNo As String
Set ws = Sheets("Complaints")
Set ws1 = Sheets("AddRow")
Set tbl = ws.ListObjects("ComplaintsTable")
Set newRow = tbl.ListRows.Add
With newRow
.Range(1) = ws1.Range("C1").Value 'Complaint Yes/No
.Range(11) = ws1.Range("C6").Value 'PCE Yes/No
.Range(3) = ws1.Range("C4").Value 'Subject
.Range(20) = ws1.Range("C5").Value 'Entered Date
End With
'To add Hyperlink
If (ws1.Range("C1").Value = "Yes") Then
Call ActiveSheet.Hyperlinks.Add(newRow.Range(2), ws1.Range("F3").Value, "", "Open in EtQ", ws1.Range("F2").Value)
End If
If (ws1.Range("C6").Value = "Yes") Then
Call ActiveSheet.Hyperlinks.Add(newRow.Range(12), ws1.Range("F8").Value, "", "Open in EtQ", ws1.Range("F7").Value)
'To add hyperlink and PCE Number
End If
End Sub
The problem with the code is that "newRow.Range" does not work with the " hyperlinks.add". I fugered out this a few days ago but I didn't get a chance to post this.
I appreciate all your help!
Related
Good Morning everyone,
I am facing a strange Problem in Excel VBA.
So, I have this minimal Example. The only thing it's supposed to do is, add a Button to the Rightklick context menu. This button should then select a cell.
I searched a bit on StackOverflow and found a solution to passing string arguments in .onaction. But then it gets tricky. I can assign a Range and I can Print the Address and the second Argument in a Mesgbox. But I can't set Breakpoints and even stop doesn't work, nor will .select or .ScrollColumn do anything.
To Replicate just copy the Following code into a standard Module and Execute AddContextmenu to add the Button to the Contextmenu.
Option Explicit
Public Sub AddContextmenu()
Dim MySubMenu As CommandBarControl
Dim i As Long
'Clear Previous Menu Items
For Each MySubMenu In Application.CommandBars("Cell").Controls
If Not MySubMenu.BuiltIn Then
MySubMenu.Delete
End If
Next
'add menu
AddScrollButtons Application.CommandBars("Cell"), 1
End Sub
Public Sub AddScrollButtons(ByVal ContextMenu As CommandBar, ByVal baseindex As Long)
Dim cbb As CommandBarButton
Dim sFunction As String
'Add Button
Set cbb = ContextMenu.Controls.Add(Temporary:=True)
With cbb
sFunction = BuildProcArgString("ScrolltoColTest", "$F$10", "TestArg") ' Get Onaction string
.OnAction = sFunction
.Caption = "Scroll Tester"
.Style = msoButtonAutomatic
End With
End Sub
Function BuildProcArgString(ByVal ProcName As String, ParamArray Args() As Variant)
Dim tempArg As Variant
Dim temp As String
For Each tempArg In Args
temp = temp + Chr(34) + tempArg + Chr(34) + ","
Next
BuildProcArgString = "'" & ThisWorkbook.Name & "'!" & ProcName + "(" + Left(temp, Len(temp) - 1) + ")" ' (Workbook has to be included to ensure that the sub will be executed in the correct workbook)
End Function
Public Sub ScrolltoColTest(Addr As String, OtherArg As String)
Dim cell As Range
Set cell = ActiveSheet.Range(Addr) 'Get Cell that sould be selected from Addr
MsgBox cell.Address & vbNewLine & OtherArg 'Test if the Arguments have been passed correctly and the cell has been assigned
Stop 'Why doesn' this stop?
cell.Select 'Why doesn't this do anything
ActiveWindow.ScrollColumn = cell.Column 'Why doesn't this do anything
End Sub
As you will see in ScrolltoColTest the Part after the Msgbox will not work at all.
Does anyone know why that happens?
I'm programming a Macro in VB for Excel 2013 that search for coincidences in different worksheets, and add a link to the cells that match.
I'm havin torubles to insert the link in the cell, since the link must be different for a range of cells, I need help here.
Here is my code
Dim bufferDetails As String
Dim tmpCell As String
Dim spot As String
Dim cell As Variant
Dim cellSpots As Variant
For Each cell In Worksheets("MMS-Locations").Range("D2:D1833")
If (cell.Value2 = "NULL") Then
cell.Value2 = "NULL"
Else
tmpCell = cell.Text
'A62
If (Left(tmpCell, 3) = "A62") Then
spot = spotName(tmpCell)
For Each cellSpots In Worksheets("DetailedMap").Range("G60:CF123")
If (cellSpots.Value2 = spot) Then
For Each linkToSpot In Worksheets("MMS-Locations").Range("H2:H1833")
Worksheets("MMS-Locations").Hyperlinks.Add _
Anchor:=Range(linkToSpot), _
Address:="http://example.microsoft.com", _
ScreenTip:="Microsoft Web Site", _
TextToDisplay:="Microsoft"
Next linkToSpot
Debug.Print ("Encontrado " + cellSpots)
End If
Next cellSpots
End If
End If
Next cell
End Sub
Function spotName(fullName As String) As String
Dim realSpot As String
Dim lenght As Integer
lenght = Len(fullName) - 3
realSpot = Right(fullName, lenght)
spotName = realSpot
End Function
As I was thinking the linkToSpot variable contains the actual cell in the range, so I can move my selection of the sell, but my code fails in there with this error:
Error in the Range method of the '_Global' object,
Just for reference, here is what I use to convert a phone number to an email for texting..setting it as a hyperlink in the current cell.
ActiveCell.Value = myNumbr
Set myRange = ActiveCell
ActiveSheet.Hyperlinks.Add anchor:=myRange, Address:="mailto:" & myRange.Value, TextToDisplay:=myRange.Value`
Keep your code simple to start with, until you find a working script, then add other items. Make good use of the F8 key to step through your code to find out exactly where an error occurs.
I'm trying to apply a macro when value from a cell change. I've this code in the Dashboard Sheet :
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Target.Worksheet.Range("FilterChoice")) Is Nothing Then Call ApplyDashboardFilter
End Sub
The trigger works fine and the macro is executed right after, but don't know why I got an error on the Advanced filter function : "application-defined or object-defined error"
Option Explicit
Sub ApplyDashboardFilter()
Dim rng As Range
Dim filterName As String
Dim tableName As String
filterName = "Filter" & Replace(Sheets("Dashboard").Range("FilterChoice").Value, " ", "")
tableName = filterName + "[#All]"
Sheets("Dashboard").Activate
Sheets("Dashboard").Columns("A:AN").Cells.Clear
Sheets("Critical Flows").Range("ClosingFlows[#All]").AdvancedFilter Action:=xlFilterCopy _
, CriteriaRange:=Sheets(filterName).Range(tableName) _
, CopyToRange:=Sheets("Dashboard").Range("A1"), Unique:=False
Set rng = Range(Range("A1"), Range("A1").CurrentRegion)
ActiveSheet.ListObjects.Add(xlSrcRange, rng, , xlYes).Name = _
"Flows" & filterName
ActiveSheet.ListObjects("Flows" & filterName).TableStyle = "TableStyleMedium3"
If Sheets("Dashboard").Range("FilterChoice").Value = "Orchestrated" Then
Call ApplyFlormulaRunbookName
End If
End Sub
The macro works when triggered by a button on Dashboard sheet.
Am I missing something ?
Thanks in advance,
EDIT :
Well, something weird happened. I just re-opened the file after a break and it worked.
I suspect something happened with the ActiveSheet and / or a conflict with another workbook since I'm playing with 2 other workbooks and 10 sheets overall.
Is it possible ?
I've added as an answer as the comments won't allow me to format correctly. This code just references the sheets, rather than selecting them:
Sub ApplyDashboardFilter()
Dim rng As Range
Dim filterName As String
Dim tableName As String
Dim wrkShtDash As Worksheet
Dim wrkShtFlows As Worksheet
Set wrkShtDash = ThisWorkbook.Worksheets("Dashboard")
Set wrkShtFlows = ThisWorkbook.Worksheets("Critical Flows")
filterName = "Filter" & Replace(wrkShtDash.Range("FilterChoice").Value, " ", "")
tableName = filterName + "[#All]"
wrkShtDash.Columns("A:AN").Cells.Clear
wrkShtFlows.Range("ClosingFlows[#All]").AdvancedFilter Action:=xlFilterCopy _
, CriteriaRange:=ThisWorkbook.Worksheets(filterName).Range(tableName) _
, CopyToRange:=wrkShtDash.Range("A1"), Unique:=False
Set rng = wrkShtDash.Range(wrkShtDash.Range("A1"), wrkShtDash.Range("A1").CurrentRegion)
wrkShtDash.ListObjects.Add(xlSrcRange, rng, , xlYes).Name = _
"Flows" & filterName
wrkShtDash.ListObjects("Flows" & filterName).TableStyle = "TableStyleMedium3"
If wrkShtDash.Range("FilterChoice").Value = "Orchestrated" Then
Call ApplyFlormulaRunbookName 'Spelt correctly?
End If
End Sub
Note: I haven't tested the code, it's just showing that you don't have to activate the sheet before working on it and is explicit about which file or sheet it's working with - ThisWorkbook means the file that the VBA code is in.
I understand what the problem is, but i don't have a clue on how to solve it...
So what I am doing is that I click on a button (addSceneButton) in my worksheet("costing") and it is going to insert a copy of another sheet("Scene Template") just above of the button (addSceneButton). It is also gonna create a button (deleteSceneButton) at the rightmost of the previously inserted sheet.
This button (deleteSceneButton), when clicked, must delete the region next to it.
It works ok if I only add 1 scene. But when I add more then one and then click on the deleteButton, it will automatically delete the last sheet inserted.
And when I want to delete a second one, it gives me the "Object Required" Error.
It must be because I overwrite the delteButtonPos instead of creating one dynamically but I dont know how.
Could someone help me on this ?
Here is my code
Public buttonPos As Range
Public deleteButtonPos As Range
Public deleteButton As Object
Private Sub AddSceneButton_Click()
Set buttonPos = Sheets(AddSceneButton.Parent.Name).Cells(AddSceneButton.TopLeftCell.Row - 1, _
AddSceneButton.TopLeftCell.Column)
Sheets("Scene Template").Activate
Sheets("Scene Template").Select
Sheets("Scene Template").Range("A1:H22").Select
Selection.Copy
Sheets("Costing").Select
buttonPos.Select
Selection.Insert Shift:=xlDown
'Insert the Add Scene Button
'Insert the Delete Button
Set deleteButtonPos = Selection.Range("H1")
Set deleteButton = ActiveSheet.Buttons.Add(deleteButtonPos.Left, _
deleteButtonPos.Top, _
deleteButtonPos.Width, _
deleteButtonPos.Height)
With deleteButton
.Caption = "Delete Button"
.Name = "deleteButtonFunct"
.OnAction = "Sheet1.deleteButtonFunct_Click"
End With
End Sub
Private Sub deleteButtonFunct_Click()
deleteButtonPos.Select
Range(Selection, Selection.End(xlDown)).Select
Selection.EntireRow.Delete
buttonPos.Select
End Sub
The reason why your code is throwing object required is because it cannot find the Button. So to correct that we need to set the button again after the first deletion.
Here I have added 3 more variables as public introw, selnum, colnum.
There is no change in the AddSceneButton sub part.
I have added an additional Check function to set the button again and to set the row number and column number correctly.
Check function is called within deleteButtonFunct sub, so that everytime when the delete button is clicked, it deletes the current/latest rows which is copied
to the sheet and sets a new delete button to the last column.
And if the Row number is 1, then there is no need to set an additional button, hence the condition inside the check function.
I have modified your code. Please find the updated code.
Public buttonPos As Range
Public deleteButtonPos As Range
Public deleteButton As Object
Public introw, selnum, colnum As Integer
Private Sub AddSceneButton_Click()
Set buttonPos = Sheets(AddSceneButton.Parent.Name).Cells(AddSceneButton.TopLeftCell.Row - 1, _
AddSceneButton.TopLeftCell.Column)
Sheets("Scene Template").Activate
Sheets("Scene Template").Select
Sheets("Scene Template").Range("A1:H22").Select
Selection.Copy
Sheets("Costing").Select
buttonPos.Select
Selection.Insert Shift:=xlDown
'Insert the Add Scene Button
'Insert the Delete Button
Set deleteButtonPos = Selection.Range("H1")
Set deleteButton = ActiveSheet.Buttons.Add(deleteButtonPos.Left, _
deleteButtonPos.Top, _
deleteButtonPos.Width, _
deleteButtonPos.Height)
With deleteButton
.Caption = "Delete Button"
.Name = "deleteButtonFunct"
.OnAction = "Sheet1.deleteButtonFunct_Click"
End With
End Sub
Private Sub deleteButtonFunct_Click()
deleteButtonPos.Select
Range(Selection, Selection.End(xlDown)).Select
introw = Selection.Count
Selection.EntireRow.Delete
buttonPos.Select
Call check
End Sub
Function check()
rownum = ActiveCell.Row
colnum = ActiveCell.Column
selnum = rownum - introw
If (rownum > 1) Then
Cells(selnum, colnum).Select
Set deleteButtonPos = Selection.Range("H1")
Set deleteButton = ActiveSheet.Buttons.Add(deleteButtonPos.Left, _
deleteButtonPos.Top, _
deleteButtonPos.Width, _
deleteButtonPos.Height)
With deleteButton
.Caption = "Delete Button"
.Name = "deleteButtonFunct"
.OnAction = "Sheet1.deleteButtonFunct_Click"
End With
End If
End Function
The code is tested and is working fine.
Hope this should help :)
The range variables buttonPos and deleteButtonPos only ever seem to contain a single cell ref. When you add the 2nd scene you need to add another cell to the range using the Application.Union() method. You'll need some way to associate the scenes to the respective delete button.
If you add the following code to a new module, it shows how you can uniquely handle all your dynamic buttons.
My example uses a number (count) to track and index the new buttons, it could be modified fairly simply to be a cell reference (to range you want to delete in your example).
Public Count As Integer ' Used to index the controls in my example
Sub addButton()
Dim P As Range: Set P = Selection
Dim B As Object
Dim S As String: S = CStr(Count) ' string representation of count
Set B = ActiveSheet.Buttons.Add(P.Left, P.Top, P.Width, P.Height)
With B
.Caption = "Id#" & S
.Name = "Id" & S
.onAction = "'onAction " & Chr(34) & S & Chr(34) & "'"
End With
Count = Count + 1 ' Increase the counter
End Sub
Public Sub onAction(ByVal Index As String)
MsgBox "You Pressed Button #" & Index & "!", vbOKOnly, "Action"
End Sub
I already have a macro that creates sheets and some other stuff. After a sheet has been created do I want to call another macro that copies data from a second excel (its open) to first and active excel file.
First I want to copy to headers, but I cant get that to work - keep getting errors.
Sub CopyData(sheetName as String)
Dim File as String, SheetData as String
File = "my file.xls"
SheetData = "name of sheet where data is"
# Copy headers to sheetName in main file
Workbooks(File).Worksheets(SheetData).Range("A1").Select # fails here: Method Select for class Range failed
Workbooks(File).Worksheets(SheetData).Range(Selection, Selection.End(xlToRight)).Select
Workbooks(File).Worksheets(SheetData).Selection.Copy ActiveWorkbook.Sheets(sheetName).Cells(1, 1)
End Sub
What is wrong ?
I really want to avoid having to make "my file.xls" active.
Edit: I had to give it up and copy the SheetData to target file as a new sheet, before it could work.
Find and select multiple rows
Two years later (Found this on Google, so for anyone else)... As has been mentioned above, you don't need to select anything. These three lines:
Workbooks(File).Worksheets(SheetData).Range("A1").Select
Workbooks(File).Worksheets(SheetData).Range(Selection, Selection.End(xlToRight)).Select
Workbooks(File).Worksheets(SheetData).Selection.Copy ActiveWorkbook.Sheets(sheetName).Cells(1, 1)
Can be replaced with
Workbooks(File).Worksheets(SheetData).Range(Workbooks(File).Worksheets(SheetData). _
Range("A1"), Workbooks(File).Worksheets(SheetData).Range("A1").End(xlToRight)).Copy _
Destination:=ActiveWorkbook.Sheets(sheetName).Cells(1, 1)
This should get around the select error.
Best practice is to open the source file (with a false visible status if you don't want to be bother) read your data and then we close it.
A working and clean code is avalaible on the link below :
http://vba-useful.blogspot.fr/2013/12/how-do-i-retrieve-data-from-another.html
Would you be happy to make "my file.xls" active if it didn't affect the screen? Turning off screen updating is the way to achieve this, it also has performance improvements (significant if you are doing looping while switching around worksheets / workbooks).
The command to do this is:
Application.ScreenUpdating = False
Don't forget to turn it back to True when your macros is finished.
I don't think you need to select anything at all. I opened two blank workbooks Book1 and Book2, put the value "A" in Range("A1") of Sheet1 in Book2, and submitted the following code in the immediate window -
Workbooks(2).Worksheets(1).Range("A1").Copy Workbooks(1).Worksheets(1).Range("A1")
The Range("A1") in Sheet1 of Book1 now contains "A".
Also, given the fact that in your code you are trying to copy from the ActiveWorkbook to "myfile.xls", the order seems to be reversed as the Copy method should be applied to a range in the ActiveWorkbook, and the destination (argument to the Copy function) should be the appropriate range in "myfile.xls".
I was in need of copying the data from one workbook to another using VBA. The requirement was as mentioned below 1. On pressing an Active X button open the dialogue to select the file from which the data needs to be copied. 2. On clicking OK the value should get copied from a cell / range to currently working workbook.
I did not want to use the open function because it opens the workbook which will be annoying
Below is the code that I wrote in the VBA. Any improvement or new alternative is welcome.
Code: Here I am copying the A1:C4 content from a workbook to the A1:C4 of current workbook
Private Sub CommandButton1_Click()
Dim BackUp As String
Dim cellCollection As New Collection
Dim strSourceSheetName As String
Dim strDestinationSheetName As String
strSourceSheetName = "Sheet1" 'Mention the Source Sheet Name of Source Workbook
strDestinationSheetName = "Sheet2" 'Mention the Destination Sheet Name of Destination Workbook
Set cellCollection = GetCellsFromRange("A1:C4") 'Mention the Range you want to copy data from Source Workbook
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
.Show
'.Filters.Add "Macro Enabled Xl", "*.xlsm;", 1
For intWorkBookCount = 1 To .SelectedItems.Count
Dim strWorkBookName As String
strWorkBookName = .SelectedItems(intWorkBookCount)
For cellCount = 1 To cellCollection.Count
On Error GoTo ErrorHandler
BackUp = Sheets(strDestinationSheetName).Range(cellCollection.Item(cellCount))
Sheets(strDestinationSheetName).Range(cellCollection.Item(cellCount)) = GetData(strWorkBookName, strSourceSheetName, cellCollection.Item(cellCount))
Dim strTempValue As String
strTempValue = Sheets(strDestinationSheetName).Range(cellCollection.Item(cellCount)).Value
If (strTempValue = "0") Then
strTempValue = BackUp
End If
Sheets(strDestinationSheetName).Range(cellCollection.Item(cellCount)) = strTempValue
ErrorHandler:
If (Err.Number <> 0) Then
Sheets(strDestinationSheetName).Range(cellCollection.Item(cellCount)) = BackUp
Exit For
End If
Next cellCount
Next intWorkBookCount
End With
End Sub
Function GetCellsFromRange(RangeInScope As String) As Collection
Dim startCell As String
Dim endCell As String
Dim intStartColumn As Integer
Dim intEndColumn As Integer
Dim intStartRow As Integer
Dim intEndRow As Integer
Dim coll As New Collection
startCell = Left(RangeInScope, InStr(RangeInScope, ":") - 1)
endCell = Right(RangeInScope, Len(RangeInScope) - InStr(RangeInScope, ":"))
intStartColumn = Range(startCell).Column
intEndColumn = Range(endCell).Column
intStartRow = Range(startCell).Row
intEndRow = Range(endCell).Row
For lngColumnCount = intStartColumn To intEndColumn
For lngRowCount = intStartRow To intEndRow
coll.Add (Cells(lngRowCount, lngColumnCount).Address(RowAbsolute:=False, ColumnAbsolute:=False))
Next lngRowCount
Next lngColumnCount
Set GetCellsFromRange = coll
End Function
Function GetData(FileFullPath As String, SheetName As String, CellInScope As String) As String
Dim Path As String
Dim FileName As String
Dim strFinalValue As String
Dim doesSheetExist As Boolean
Path = FileFullPath
Path = StrReverse(Path)
FileName = StrReverse(Left(Path, InStr(Path, "\") - 1))
Path = StrReverse(Right(Path, Len(Path) - InStr(Path, "\") + 1))
strFinalValue = "='" & Path & "[" & FileName & "]" & SheetName & "'!" & CellInScope
GetData = strFinalValue
End Function