VBA Pathfinder

Dogga786

New Member
Joined
Dec 5, 2017
Messages
3
Im tryng to use sumifs formula but its not working because both the files are on Dropbox on computer and when enter the formula from my computer its using the full path "C:\User\username\dropbox\foldername" and when someone else opens the file the links dont work because their path is different "c:\users\username2\dropbox\foldername "

Is there any way you can come around this problem ? and have the formula work no matter which computer is used to open the file (both the files are on dropbox)

I was thinking maybe I can have vba code to read current user's credentials and use that in the path "C:\("current user")\dropbox\foldername\filename"

I am really new to VBAs but Im finding it very interesting

Thank you
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hello, two steps to solve this issue:

1. Add this code to a module:
Code:
Function UserName()
UserName = (Environ$("Username"))
End Function

2. Replace any instances in a formula that contains the file path with this:
CONCATENATE("c:\users",UserName(),"\dropbox\foldername")


For example:

='C:\username1\dropbox\foldername\[test.xlsx]Sheet1'!$A$1
changes to
=CONCATENATE("'C:",UserName(),"\dropbox\foldername\[test.xlsx]Sheet1'!$A$1")
 
Last edited:
Upvote 0
For some reason the forum is deleting the "slash" after "C:" in my example. Remember to include the "slash"
 
Last edited:
Upvote 0
Thank you for your help but its still not working

this is the formula i used in a cell

=SUMIFS('C:\Users\kelly\Dropbox (Essence Properties)\Projects\Job 1010 - Towne\Sales and Marketing\Sales Analysis and Pricing\Towne Pricing.xlsx'!netprice,'C:\Users\kelly\Dropbox (Essence Properties)\Projects\Job 1010 - Towne\Sales and Marketing\Sales Analysis and Pricing\Towne Pricing.xlsx'!date,">="&H6,'C:\Users\kelly\Dropbox (Essence Properties)\Projects\Job 1010 - Towne\Sales and Marketing\Sales Analysis and Pricing\Towne Pricing.xlsx'!date,"<="&EOMONTH(H6,0))

this is what i put in the VBA
Range("B41:M41").Formula = _
"=SUMIFS('Towne Pricing.xlsx'!netprice,'Towne Pricing.xlsx'!date,"">=""&R[-35]C,'Towne Pricing.xlsx'!date,""<=""&EOMONTH(R[-35]C,0))"

VBA thing works if the other workbook is open on the side then it updates the numbers

how can I tell VBA to use the function sumifs and for the file path use C:\ users\(use current users name)\ dropbox\ etc.
 
Upvote 0
I think I better understand what you are trying to do. Try this:
Code:
Sub Formula()

Dim filepath As String

filepath = "C:\Users\" & Environ$("Username") & "\Dropbox (Essence Properties)\Projects\Job 1010 - Towne\Sales and Marketing\Sales Analysis and Pricing\Towne Pricing.xlsx"

Range("B41") = "=SUMIFS('" & filepath & "'!netprice,'" & filepath & "'!date,"">="" &H6,'" & filepath & "'!date,""<=""&EOMONTH(H6,0))"
Range("B41").Copy
Range("B41:M41").PasteSpecial Paste:=xlPasteFormulas
Application.CutCopyMode = False

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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