Tricky find function used to sum columns in sheet

espenskeie

Well-known Member
Joined
Mar 30, 2009
Messages
636
Office Version
  1. 2016
Platform
  1. Windows
Hello

I have a list of tickers. I have loop running through the list and pull the tickernames.

My problem is that I need this tickername to be used to find a match in sheet wsX. If this is column D, I somehow would like to store this column number/name, and then search for next tickername and match.

Finally when the loop is done, I would like to write a formula in cell B5, something like this:

Code:
wsX.Range("B5").Formula = "=SUM(G5,D5,AB5,AT5,BX5)"

Here is what I have so far:

Code:
Sub AddSelectedStocks()
Dim wb As Workbook, wbX As Workbook
Dim ws As Worksheet, ws1 As Worksheet, ws2 As Worksheet, wsX As Worksheet
Dim colnum As Integer
Dim strPath As String, strFilename As String
Dim lr As Long




Set wb = ThisWorkbook
Set ws = wb.Sheets("Master")
Set ws1 = wb.Sheets("Graphics")


With ws
colnum = .Cells(5, .Columns.Count).End(xlToLeft).Column
End With


For i = 3 To colnum


strPath = ws.Range("C2")
strFilename = ws.Cells(5, i) & ".xlsm"


If Len(Dir(strPath & strFilename)) > 0 Then
    On Error GoTo Lst1:
    Set wbX = Workbooks.Open(strPath & strFilename)
    On Error GoTo 0
    
    Set wbX = Workbooks(strFilename)
    Set wsX = wbX.Sheets(ws.Cells(6, i))
    
    lr = ws.Cells(6, i).End(xlDown).Row
    If Not lr < 7 Then
        For j = 7 To lr
        
        
        '************
        '************
        '************
    
    
    
    wbOBX.Close True
End If


Lst1:
Next i


End Sub

Kind regards
Espen
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,207,172
Messages
6,076,919
Members
446,241
Latest member
Nhacai888b

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