Tricky Filldown with Excel VB - excel

I'm creating a column of custom urls (for import into Mailchimp) and just ran into something that is too tricky for me.
I am building a url column that takes elements from other cells. Almost all the parts of the url will be the same except one (the "Role") variable. Here is how the final url will look where the parts in bold are the variables being fed in from the spreadsheet:
http://domain.com/varPath/?PartName=varEmployee&ClientID=varClient&Role=varRole
The url column fills down the same number of rows that are in column A. Below is a list of the pertinent columns/cells in the spreadsheet for clarification:
Column A = email of all employees completing form
Cell B2 = first name (always using first entry for "varEmployee" in the url)
Cell C2 = last name (same as above)
Column D = varClient (stays the same)
Column E = varRole (THIS IS THE TRICKY ONE since I need to get the changing value)
cell I2 = varPath
The "varEmployee" variable is always going to be the same (B2 + C2)
The same is true of varClient and varPath since we only need the value from the second row (under headers). However the "varRole" variable is going to change with each row since each email in column A is associated with a different role in column E. I'm not sure how to get that value into the url string since it keeps changing. My code is below if anyone has any ideas. Thanks in advance.
Dim lngLastRow As Long
Dim varURL As String
Dim varSurvey As String
Dim varPart As String
Dim varEmployee As String
Dim varRole As String
Dim varClient As String
varURL = "https://domain.com/" + Range("I2").Text
varSurvey = Range("I2").Value
varPart = "?PartName="
varEmployee = Range("B2") + " " + Range("C2")
varRole = "&Role=" + Range("E2")
varClient = "&ClientID=" + Range("D2").Text
varFinal = (varURL & varSurvey & varPart & varEmployee & "&ClientID=" & varClient)
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("F2:F" & lngLastRow).Value = voxFinal

Ok, I read a few more 'for next' posts after seeing Rob's reply and I changed the approach and wrote a slightly different script. This is what I ended up cobbling together which seems to work:
Sub buildURL()
'
' buildURL Macro
'
'
Dim N As Long, i As Long, j As Long
Dim voxURL As String
Dim varSurvey As String
Dim varPart As String
Dim varEmployee As String
Dim varRole As String
Dim varClient As String
varURL = "https://domain.com/" + Range("I2").Text
varSurvey = Range("I2").Value
varPart = "?PartName="
varEmployee = Range("B2") + " " + Range("C2")
varRole = "&Role="
varClient = "&ClientID=" + Range("D2").Text
varFinal = (varURL & varSurvey & varPart & varEmployee & varClient & varRole)
N = Cells(Rows.Count, "A").End(xlUp).Row
j = 2
For i = 2 To N
If Not IsEmpty(Range("A" & i).Value) Then
Cells(j, "F").Value = voxFinal & Cells(i, "E").Value
j = j + 1
End If
Next i
End Sub

Related

Trying to Concatenate 2 Columns from the Table Directly VBA

I have been trying to Concatenate two Columns directly from the Table1. But i really do not know how. I have tried and make below code.
But I have been creating first 2 helping Column in in "DI" and "DJ" to make this thing work.
I do not want to use these two helping columns directly wants the concatenate result in "DK2"
All help will be appreciaed.
Dim O As String
Dim P As String
O = "Milestone"
P = "Task"
Sheet1.Range("Table1[" & O & "]").Copy
Sheet2.Range("DI2").PasteSpecial xlPasteValues
Sheet1.Range("Table1[" & P & "]").Copy
Sheet2.Range("DJ2").PasteSpecial xlPasteValues
For i = 2 To Cells(Rows.Count, "DH").End(xlUp).Row
Sheet2.Cells(i, "DK").Value = Sheet2.Cells(i, "DI").Value & "" & Sheet2.Cells(i, "DJ").Value
Next i
Here is the example Picture
Try this.
Range("DK2").Resize(Sheet2.ListObjects("Table1").ListRows.Count) = Application.Evaluate("Table1[Milestone]&Table1[Task]")
EDIT: I've seen #norie's answer and it is simpler and more efficient than mine. I'll keep my answer here for anyone who is curious, but I recommend using his solution.
The trick is to use =INDEX(YOUR_TABLE[YOUR_COLUMN]], YOUR_ROW_STARTING_FROM_1) in order to obtain the cell contents that you needed.
Here you are your code edited:
Original
Dim O As String
Dim P As String
Dim i As Integer
O = "Milestone"
P = "Task"
For i = 1 To Application.Evaluate("ROWS(Table1[" & O & "])")
Sheet2.Cells(i, "DK").Value = Application.Evaluate("INDEX(Table1[" & O & "], " & i & ") & INDEX(Table1[" & P & "], " & i & ")")
Next i
Optimized
Dim O As String
Dim P As String
Dim i As Integer
O = "Milestone"
P = "Task"
' Disable formula recalculation while trying to add our data to increase performance
Application.Calculation = xlManual
' Disable screen updating while trying to add our data to improve performance
Application.ScreenUpdating = False
For i = 1 To Application.Evaluate("ROWS(Table1[" & O & "])")
Sheet2.Cells(i, "DK").Value = Application.Evaluate("INDEX(Table1[" & O & "], " & i & ") & INDEX(Table1[" & P & "], " & i & ")")
Next i
' Enable again formula's automatic evaluation.
Application.Calculation = xlAutomatic
' Enable again screen updating
Application.ScreenUpdating = True
Optimized using only Formulas (this performs better that the others)
Dim O As String
Dim P As String
Dim i As Integer
O = "Milestone"
P = "Task"
' Disable formula recalculation while trying to add our data to increase performance
Application.Calculation = xlManual
' Disable screen updating while trying to add our data to improve performance
Application.ScreenUpdating = False
For i = 1 To Application.Evaluate("ROWS(Table1[" & O & "])")
Sheet2.Cells(i, "DK").FormulaR1C1 = "=INDEX(Table1[" & O & "], " & i & ") & INDEX(Table1[" & P & "], " & i & ")"
Next i
' Enable again formula's automatic evaluation.
Application.Calculation = xlAutomatic
' Enable again screen updating
Application.ScreenUpdating = True
Optimized using Formulas and then converting back to values
Dim O As String
Dim P As String
Dim i As Integer
O = "Milestone"
P = "Task"
' Disable formula recalculation while trying to add our data to increase performance
Application.Calculation = xlManual
' Disable screen updating while trying to add our data to improve performance
Application.ScreenUpdating = False
For i = 1 To Application.Evaluate("ROWS(Table1[" & O & "])")
Sheet2.Cells(i, "DK").FormulaR1C1 = "=INDEX(Table1[" & O & "], " & i & ") & INDEX(Table1[" & P & "], " & i & ")"
Next i
' Enable again formula's automatic evaluation.
Application.Calculation = xlAutomatic
' Enable again screen updating
Application.ScreenUpdating = True
' Convert from formulas to values
Range("DK:DK").Copy
Range("DK:DK").PasteSpecial xlPasteValues
This can be done directly in the worksheet by using the Index function
Reference first cell in the table: =INDEX(Table1,1,1)
Concatenate cell 1 and 2 values: =INDEX(Table1,1,1)&INDEX(Table1,1,2)
It gets slightly more complicated if you want to be able to copy formulae across or down as you need to reference the current cell location
Reference first cell in the table using offsets: =INDEX(Table1,ROW()-X,COLUMN()-Y) where X, Y (minus data location offsets) are the numerical row/column of the cell where you have placed the formula.
i.e. if placing the formula in E2 to reference Table1 cell(1,1) => =INDEX(Table1,ROW()-1,COLUMN()-4)
where Column E=> Offset 4, Row 2 => Offset 1
or: =INDEX(Table1,ROW()-ROW($E$2)+1,COLUMN()-COLUMN($E$2)+1)
You can now autofill the formula down or across
Concatenate List Columns
With your amount of data both solutions may seem equally efficient. I've tested it with a million rows of random numbers from 1 to 1000, and the first solution took about 3.5 seconds, while the second took about 5.5 seconds on my machine. The first solution is just a more elaborate version of norie's answer.
In this solution, you can add more columns (headers) and use a delimiter. While adding more columns the difference in the efficiencies will become more apparent, while when adding more characters to the delimiter, the efficiencies will decrease seemingly equally.
The Code
Option Explicit
Sub concatListColumnsEvaluate()
Dim dTime As Double: dTime = Timer
' Define constants.
Const TableName As String = "Table1"
Const HeadersList As String = "Milestone,Task"
Const dFirst As String = "D2"
Const Delimiter As String = ""
' Determine table rows count.
Dim rCount As Long: rCount = Sheet1.ListObjects(TableName).ListRows.Count
' Create Evaluate Expression String.
Dim Headers() As String: Headers = Split(HeadersList, ",")
Dim tUpper As Long: tUpper = UBound(Headers)
Dim evString As String
Dim t As Long
If Len(Delimiter) = 0 Then
For t = 0 To tUpper
evString = evString & TableName & "[" & Headers(t) & "]" & "&"
Next t
evString = Left(evString, Len(evString) - 1)
Else
For t = 0 To tUpper
evString = evString & TableName & "[" & Headers(t) & "]" & "&""" _
& Delimiter & """&"
Next t
evString = Left(evString, Len(evString) - Len(Delimiter) - 4)
End If
' Write values to Destination Range.
Sheet2.Range(dFirst).Resize(rCount).Value = Application.Evaluate(evString)
Debug.Print Timer - dTime
End Sub
Sub concatListColumnsArrays()
Dim dTime As Double: dTime = Timer
' Define constants.
Const TableName As String = "Table1"
Const HeadersList As String = "Milestone,Task"
Const dFirst As String = "D2"
Const Delimiter As String = ""
' Write values from list columns to arrays of Data Array.
Dim Headers() As String: Headers = Split(HeadersList, ",")
Dim tUpper As Long: tUpper = UBound(Headers)
Dim Data As Variant: ReDim Data(0 To tUpper)
Dim t As Long
For t = 0 To tUpper
' Either...
Data(t) = Sheet1.Range(TableName & "[" & Headers(t) & "]").Value
' ... or:
'Data(t) = Sheet1.ListObjects(TableName) _
.ListColumns(Headers(t)).DataBodyRange.Value
Next t
' Concatenate values of arrays of Data Array in Result Array.
Dim rCount As Long: rCount = UBound(Data(0), 1)
Dim Result As Variant: ReDim Result(1 To rCount, 1 To 1)
Dim r As Long
If Len(Delimiter) = 0 Then
For r = 1 To rCount
For t = 0 To tUpper
Result(r, 1) = Result(r, 1) & Data(t)(r, 1)
Next t
Next r
Else
For r = 1 To rCount
For t = 0 To tUpper
Result(r, 1) = Result(r, 1) & Data(t)(r, 1) & Delimiter
Next t
Result(r, 1) = Left(Result(r, 1), Len(Result(r, 1)) _
- Len(Delimiter))
Next r
End If
' Write values from Result Array to Destination Range.
Sheet2.Range(dFirst).Resize(rCount).Value = Result
Debug.Print Timer - dTime
End Sub

VBA Get one or more links from web (from cells)

I need this for my job. Someone wrote us a macro. This macro contains a module that take links from cells and download the files.
However. Problem is that it must be 2 rows or more that contain links.
This is nonsense for me/us as we often just download one link/file = only 1 row.
So the code must be able to handle a single row and multiple rows.
I can code a bit HTML and PHP, but that's quite long time ago.
I understand that the error "Subscript out of range" (= ext = buf(UBound(buf)) )
is because of the array. Or the way the array is being handled. But that's it.
To be honest I have not enough time to learn VBA to a point to fix this. I also only have access to these files at work...and here at work...I have to work lol.
So, help would be highly appreciated.
Sub DownloadFilefromWeb()
Dim strSavePath As String
Dim URL As String, ext As String
Dim buf, ret As Long
Dim fi As String
Dim lrow5 As Long
Dim path As String
Call Clear_All_Files_And_SubFolders_In_Folder
lrow5 = Range("A2").End(xlDown).Row
Worksheets("Link").Range("G2:G" & lrow5).Formula = "=GetURL(E2)"
j = 1
For i = 2 To lrow5
fi = Worksheets("Link").Range("A" & i).Value
URL = Worksheets("Link").Range("G" & i).Value
buf = Split(URL, ".")
ext = buf(UBound(buf))
'MsgBox ActiveWorkbook.Path
strSavePath = ActiveWorkbook.path & "\Backup\" & fi & "," & j & "." & ext
ret = URLDownloadToFile(0, URL, strSavePath, 0, 0)
j = j + 1
'If ret = 0 Then
' MsgBox "Download has been succeed!"
'Else
' MsgBox "Error"
'End If
Next i
MsgBox ("Download Completed")
End Sub
Edit:
Hard to say without knowing/seeing the layout of the sheet.
I'll guess/assume that row 1 of the Links worksheet contains headers, and that the data itself (that you want to loop through) begins from row 2.
Option Explicit
Sub DownloadFilefromWeb()
Dim strSavePath As String
Dim URL As String
Dim ret As Long
Dim Filename As String
Dim fileExtension As String
Call Clear_All_Files_And_SubFolders_In_Folder
With Worksheets("Link")
Dim lastRow As Long
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("G2:G" & lastRow).Formula = "=GetURL(E2)"
Dim fileCount As Long
fileCount = 1
Dim rowIndex As Long
For rowIndex = 2 To lastRow
Filename = .Range("A" & rowIndex).Value
URL = .Range("G" & rowIndex).Value
fileExtension = VBA.Strings.Mid$(URL, VBA.Strings.InStrRev(URL, ".", -1, vbBinaryCompare))
strSavePath = .Parent.path & "\Backup\" & Filename & "," & fileCount & fileExtension
ret = URLDownloadToFile(0, URL, strSavePath, 0, 0) ' <- Don't seem to do anything with this value. Maybe include a MsgBox alert if it returns a non-zero value.
fileCount = fileCount + 1
Next rowIndex
End With
MsgBox ("Download Completed")
End Sub
Main difference is that lastRow is assigned working from the sheet's last row upward (previously it was downward from row 2, meaning it could never be only row 2 i.e. one row of data).
lrow5 = Range("A2").End(xlDown).Row
This gets the number of rows from the current workbook and worksheet. Then in the loop:
For i = 2 To lrow5
it starts at the second row. If you want it to start at the first row (and if there is only one row), then change his to:
For i = 1 To lrow5
Note: what I don't understand in this code is the line:
Worksheets("Link").Range("G2:G" & lrow5).Formula = "=GetURL(E2)"
It seems this sets all of the hyperlinks to the URL of cell E2, i.e. to the same URL.
The GetURL function is a custom function. See http://howtouseexcel.net/how-to-extract-a-url-from-a-hyperlink-on-excel

VBA Runtime Error 9 when checking whether String has two parts

I am working with cells in a column, which have to be split. Element 1 of the string is supposed to be posted separately from Element 2 of the same string, each on another Worksheet.
String "123 ABC" -> "123" in column C and "ABC" in column D
I am running into a Runtime-Error 9 "Index out of Range" if one of the cells I am checking only contains "123" or "ABC" but no both parts.
I tried to work around it in the way you see in my code below. Needless to say it does not work.
Could one of the more experienced Excel-Gurus help me out here?
Thank you in advance for your time!
Application.ScreenUpdating = False
Dim wbInput As Workbook, wbOutput As Workbook
Set wbOutput = ActiveWorkbook
Dim wsInput As Worksheet, wsOutput As Worksheet, wsMistakes As Worksheet
Set wsOutput = wbOutput.Worksheets("FehlerVorkommen")
Set wsMistakes = wbOutput.Worksheets("NichtZuweisbar")
Dim lRowInput As Long, lRowOutput As Long, lRowMistakes As Long
Dim Lieferant As Range
Dim InputFile As String, myElements() As String
lRowOutput = wsOutput.Range("A" & Rows.Count).End(xlUp).Row
wsOutput.Range("A2:G" & lRowOutput).Clear
wsMistakes.Range("A2:G500").Clear
InputFile = Application.GetOpenFilename()
If InputFile = "Falsch" Then
Exit Sub
End If
Set wbInput = Workbooks.Open(InputFile)
Set wsInput = wbInput.Worksheets("owssvr")
lRowInput = wsInput.Range("A" & Rows.Count).End(xlUp).Row
'Get all Information
For Each Lieferant In wsInput.Columns(1).Rows("2:" & lRowInput)
If wsInput.Columns(3).Rows(Lieferant.Row) <> vbNullString Then
myElements = Split(wsInput.Columns(3).Rows(Lieferant.Row).Value, " ", 2) 'A maximum of 2 String-Parts to avoid 4-5 splits whenever there is a GmbH or AG or whatever
If IsEmpty(myElements(1)) = True Then <<<<<<<<<ERROR HERE<<<<<<<<<<<
lRowMistakes = wsMistakes.Range("A" & Rows.Count).End(xlUp).Row
NextRow = lRowMistakes + 1
wsInput.Columns(1).Rows(Lieferant.Row).Copy Destination:=wsMistakes.Columns(1).Rows(NextRow)
NextRow = NextRow + 1
Else
If IsNumeric(wsInput.Columns(1).Rows(Lieferant.Row)) = True And wsInput.Columns(1).Rows(Lieferant.Row) <> vbNullString _
And IsNumeric(wsInput.Columns(2).Rows(Lieferant.Row)) = True And wsInput.Columns(2).Rows(Lieferant.Row) <> vbNullString Then
wsInput.Columns(1).Rows("2:" & lRowInput).Copy Destination:=wsOutput.Columns(1).Rows("2:" & lRowInput) 'Task Namen
wsInput.Columns(2).Rows("2:" & lRowInput).Copy Destination:=wsOutput.Columns(2).Rows("2:" & lRowInput) 'Bestellpositionen
wsOutput.Columns(3).Rows(Lieferant.Row).Value = myElements(0) 'ID
wsOutput.Columns(4).Rows(Lieferant.Row).Value = myElements(1) 'Name
wsInput.Columns(3).Rows("2:" & lRowInput).Copy Destination:=wsOutput.Columns(5).Rows("2:" & lRowInput) 'Fehlerarten
Else 'Get all wrong inputs on separate Sheet
lRowMistakes = wsMistakes.Range("A" & Rows.Count).End(xlUp).Row
NextRow = lRowMistakes + 1
wsInput.Columns(1).Rows(Lieferant.Row).Copy Destination:=wsMistakes.Columns(1).Rows(NextRow)
NextRow = NextRow + 1
End If
End If
Else 'Get all wrong input on separate Sheet
lRowMistakes = wsMistakes.Range("A" & Rows.Count).End(xlUp).Row
NextRow = lRowMistakes + 1
wsInput.Columns(1).Rows(Lieferant.Row).Copy Destination:=wsMistakes.Columns(1).Rows(NextRow)
NextRow = NextRow + 1
End If
Next Lieferant
wbInput.Close
This line doesn't do what you think it's doing:
If IsEmpty(myElements(1)) = True
First, specifying a limit for the Split function doesn't mean that you always get that many elements in the array. Second, IsEmpty tests to see if a Variant is type VT_EMPTY, not whether a String has a value (Split returns a strongly typed array).
Just test the UBound instead:
If UBound(myElements) > 0 Then

Need code to be able to Check through current column and another column, and Match to use the same order number

if you see below, I have 3 columns, all i basically want is to check column A and Column B, if the carrier (Column A) and Date (Column B) are equal then it will have the same Order Number.
For example: In this case, A3 = A6 and B3 = B6 , so it should have the same order number as one above (160) not 163. I hope this makes it clear.
Thanks for the help. I appreciate it :)
This was quite interesting, so I went ahead and wrote some code. Copy this into a new module and change the sheetname etc. to fit to your workbook. You may also need to redefine fr (firstrow, currently set to 2). The code also currently marks all the changed order-numbers red with the line .Range("C" & r).Font.ColorIndex = 3. Delete / comment it, if you don't want that.
Sub matching()
Dim wb As Workbook
Dim tws As Worksheet
Dim keys() As String
Dim tmpKey As String
Dim pos As Integer
Dim fr, lr As Integer 'first row, last row of data
Set wb = ThisWorkbook
Set tws = wb.Worksheets("Vigmo")
fr = 2
lr = tws.Range("A1000000").End(xlUp).Row
ReDim keys(1 To lr - 1)
With tws
keys(1) = .Range("A" & fr).Value & "_" & .Range("B" & fr).Value
End With
For r = fr + 1 To lr
With tws
tmpKey = .Range("A" & r).Value & "_" & .Range("B" & r).Value
If UBound(Filter(keys, tmpKey)) >= 0 And tmpKey <> "_" Then
'found in array -> replace orderNumber
'On Error resume next
pos = Application.Match(tmpKey, keys, 0)
'On Error goto 0
.Range("C" & r).Value = .Range("C" & pos + 1).Value
.Range("C" & r).Font.ColorIndex = 3
Else
'not found -> next
End If
keys(r - 1) = tmpKey
End With
Next r
End Sub
Let me know if you have any questions as to how this code works!
Below is some code that I came up with that does what your looking for. I dont know how you are generating your order numbers but I assumed they are already present. Hope this helps you :)
Sub OrderNumber()
Dim SearchTerm As String
Dim DateTerm As Date
Dim NumberOfEntries As Long
Dim wks As Excel.Worksheet
Set wks = Worksheets("Sheet1") '<==== Sets the workbook. change it to what yours is called
NumberOfEntries = Application.WorksheetFunction.CountA(wks.Range("A:A")) '<=== Find the number of entries
For x = 2 To NumberOfEntries '<==== Goes through all the entries
SearchTerm = wks.Cells(x, 1) '<===== The Search term (Carrier)
DateTerm = CDate(wks.Cells(x, 2)) '<==== The search Date
For y = x To NumberOfEntries '<===== goes through everything below the search term to speed things up
If wks.Cells(y, 1) = SearchTerm And CDate(wks.Cells(y, 2)) = DateTerm Then '<=== If the name and the date match then
wks.Cells(y, 3) = wks.Cells(x, 3) '<==== Copy the order number
End If
Next y
Next x
End Sub
Just put this in a module or wherever you want but I made it in a module.
G

Run time Error '1004' using .Formula

I'm building an master excel file that is designed to gather data from lots of other excel files that are stored in the business Dropbox files and place them in the 2nd sheet of the master file. I built a original version on my local computer and that worked perfectly (the path3 variable) but once I tried to convert it based on a changing file path (because each user will have a different path from their PC) I am getting the run time error. The formula defined by path2 is what I have been trying to use but even though the variable seems to be holding the right value (I tested it by having it write out the values) it doesn't seem to be able to move the data, throwing the above error and highlighting the "rngdest.Formula = Chr(61) & path2" line. I really don't have any idea what is causing this and I have spent several days trying different approaches but to no avail so any ideas, solutions or links to already solved (I have spent a long time searching but haven't found anything) would be very much appreciated.
I've included the whole of the code for completeness, I think I've removed most of the redundant code that I left in but there may be some still left. If you need any clarifications on the code please let me know. Thanks for any potential help
Private Sub CommandButton2_Click()
Dim counter As Integer
Dim i As Long
Dim j As Long
Dim k As Long
Dim l As Long
Dim a As Integer
Dim z As Integer
Dim y As Integer
Dim p As Integer
Dim Names() As String
Dim Fix1() As String
Dim path3 As String
Dim path2 As String
Dim SheetName As String
Dim c As Range
Dim found As Range
Dim BookName As String
Dim var1 As String
Dim rngdest As Range
Dim rngsource As Range
Dim cell As String
Dim adjust As Integer
Dim adjust2 As Integer
Dim rngname As Range
Dim colNo As Integer
Dim fin As String
Dim fin2 As String
Dim fin3 As String
Dim comp As String
Dim teststring As String
Dim currentWb2 As Workbook
Set currentWb2 = ThisWorkbook
MsgBox "Excel will now update the sheet, please be patient as this can take a few minutes. You will be notified once it is complete"
ReDim Fix1(1 To 4)
Fix1(1) = "A-F"
Fix1(2) = "G-L"
Fix1(3) = "M-R"
Fix1(4) = "S-Z"
counter = 0
With ActiveSheet
i = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
ReDim Names(1 To i, 1 To 4)
With ActiveSheet
For k = 1 To 4
For a = 2 To i
Names(a, k) = Cells(a, k).Value
Next a
Next k
End With
SheetName = "Analysis"
BookName = "Outcomes Final.xlsm"
For p = 1 To 4
fin2 = Split(Cells(, p).Address, "$")(1)
With ActiveSheet
l = .Cells(.Rows.Count, fin2).End(xlUp).Row
End With
For z = 1 To l
counter = counter + 1
fin = Split(Cells(, counter).Address, "$")(1)
currentWb2.Sheets("Sheet2").Range("" & fin & "1") = Names(z, p)
For y = 1 To 34
adjust = y + 1
cell = "$B$" & y & ""
If z = 1 Then
Else
teststring = GetPath()
teststring = teststring & "\Clients\"
path3 = "'C:\Users\Lewis\Documents\Outcomes\Floating Support\Clients\" & Fix1(p) & "\" & Names(z, p) & "\[Outcomes Final.xlsm]Analysis'!" & cell & ""
path2 = teststring & Fix1(p) & "\" & Names(z, p) & "\Outcomes\[Outcomes Final.xlsm]Analysis'!" & cell & ""
End If
Set rngdest = currentWb2.Sheets("Sheet2").Range("" & fin & "" & adjust & "")
Set rngsource = Range("B" & y & "")
rngdest.Formula = Chr(61) & path2
Next y
Next z
Next p
currentWb2.Sheets("Sheet2").Columns(1).EntireColumn.Delete
currentWb2.Sheets("Sheet1").Range("A1:D35").Interior.ColorIndex = 0
For j = 1 To counter
fin3 = Split(Cells(, j).Address, "$")(1)
If currentWb2.Sheets("Sheet2").Range("" & fin3 & "35") = "1" Then
With currentWb2.Sheets("Sheet1").Range("A1:D35")
comp = currentWb2.Sheets("Sheet2").Range("" & fin3 & "1")
Set c = .Find(comp, LookIn:=xlValues)
If Not c Is Nothing Then
c.Interior.ColorIndex = 3
End If
End With
End If
Next j
MsgBox "The update is now complete, please click on sheet 2 to view the data. All clients in red have not been properly completed"
End Sub

Resources