VBA Help with changing tracker on different excel sheet

collin8579

New Member
Joined
Oct 31, 2017
Messages
20
Good Morning,
I have an excel sheet I'm building that does budgeting for specific types of projects. I have most of the VBA worked out for that. The part I'm having issues with is updating an exteral excel tracker.
This is the script to create the tracker if it doesn't exist:

Sub trackerTest()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Set objWS = CreateObject("WScript.Shell")
strDesktopPath = objWS.SpecialFolders("Desktop")
Workbooks.Open Filename:=strDesktopPath & "\sites\Tracker.xlsx"
Windows("Tracker.xlsx").Activate
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

The main sheet I'm working on will have a dynamic name based on properties within the sheet. IE Job Number, Site Name, etc
This is a snippet from that save code (no issues with this):
ActiveWorkbook.SaveCopyAs Filename:= _
strDesktopPath & "\sites\BU# " & BUN & " JOB# " & JDE & " " & STE & "\BU# " & BUN & " JOB# " & JDE & " " & STE & " Main.xlsm"


The Tracker will have a line for each Job/Contractor and will look similar to this (ignore the strikethrough)

[TABLE="width: 870"]
<tbody>[TR]
[TD]BU
[/TD]
[TD]JDE #
[/TD]
[TD]ALT SITE ID
[/TD]
[TD]SCOPE
[/TD]
[TD]GEN CONTRACTOR
[/TD]
[TD]ORIG AMOUNT
[/TD]
[TD]NEW AMOUINT
[/TD]
[TD]DATE SOV REC'D
[/TD]
[TD]DATE POR SNT
[/TD]
[/TR]
[TR]
[TD="align: right"]<strike>111111</strike>
[/TD]
[TD="align: right"]<strike>222222 </strike>
[/TD]
[TD]<strike>SX33333</strike>
[/TD]
[TD]<strike>RF MOD</strike>
[/TD]
[TD]<strike>YYYYY</strike>
[/TD]
[TD="align: right"]<strike>$3,398.90</strike>
[/TD]
[TD][/TD]
[TD="align: right"]<strike>2-May</strike>
[/TD]
[TD="align: right"]<strike>3-May</strike>
[/TD]
[/TR]
[TR]
[TD="align: right"]111111
[/TD]
[TD="align: right"]222222
[/TD]
[TD]SX3333
[/TD]
[TD]RF MOD
[/TD]
[TD]XXXXX
[/TD]
[TD="align: right"]$3,697.09
[/TD]
[TD][/TD]
[TD="align: right"]4-Aug
[/TD]
[TD="align: right"]4-Aug
[/TD]
[/TR]
</tbody>[/TABLE]


What I need is in my main sheet (which has the dynamic name above) able to edit the lines on the tracker. I don't need it to delete lines but I need it able to differentiate based on the Contractor/ Job number/ Amount ---
I have three buttons on my main sheet. Tracker POR Sent, Tracker - Budget Out, and Tracker - PO Sent
So when I click one it goes to the tracker sheet (That was created if it wasn't there already), and either update an existing tracker line based on its search or adds a new tracker line if it isn't there yet. Then updates a section of the tracker based on the button - a Date in the POR sent, Budget out, or PO Sent section

Below is the code I'm experimenting with to find the lines on the tracker - It works in theory but when I put variables in noted sections it doesn't work anymore

Sub linesearch()
Set objWS = CreateObject("WScript.Shell")
strDesktopPath = objWS.SpecialFolders("Desktop")
Workbooks.Open Filename:=strDesktopPath & "\sites\Tracker.xlsx"
Windows("Tracker.xlsx").Activate
Dim rngFound As Range
Dim strFirst As String
Dim Joba As String
Joba = ThisWorkbook.Sheets("Project Selection").Range("C5").Value
Dim amnta As String
amnta = ThisWorkbook.Sheets("Project Selection").Range("C11").Value
Set rngFound = Columns("A").Find(BU, Cells(Rows.Count, "A"), xlValues, xlWhole)
If Not rngFound Is Nothing Then
strFirst = rngFound.Address
Do
If LCase(Cells(rngFound.Row, "B").Text) = LCase(Joba) And _
LCase(Cells(rngFound.Row, "F").Text) = LCase(amnta) _ **********This Joba and amnta are names in the main worksheet to determine if tracker has viable line - This whole sub works when I have specific text in this section but not named items??*****
Then
'Found a match
MsgBox "Found a match at: " & rngFound.Row & Chr(10) & _
"Value in column C: " & Cells(rngFound.Row, "C").Text & Chr(10) & _
"Value in column D: " & Cells(rngFound.Row, "D").Text
End If
Set rngFound = Columns("A").Find(BU, rngFound, xlValues, xlWhole)
Loop While rngFound.Address <> strFirst
End If
Set rngFound = Nothing
End Sub


Now, This was pilfered from an online source so I get the basics of what it is doing but not the whole understanding.

My biggest issue is when using the main sheet (dynamic name) - Going into the tracker and finding the line I need or creating it - then coming back to the main sheet
I don't really know how to do that

So my questions:
When I switch the active sheet to tracker.xlsx how do I go back to the dynamic name sheet?
What is the best way to update the tracker lines? I'm fairly confident I can find the row number with the above script if I get it working with the named items (amnta, joba) which correspond with a cell on the main sheet.
I want it to be able to add lines to the tracker if they don't exist - and it has a variable number of lines (can add them in the beginning)

Any help would be appreciated!
[TABLE="width: 536"]
<tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"][/TD]
[TD="align: right"]<strike> </strike>
[/TD]
[TD]<strike></strike>
[/TD]
[TD]<strike></strike>
[/TD]
[TD]<strike></strike>
[/TD]
[TD="align: right"]<strike></strike>
[/TD]
[/TR]
[TR]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top