Macro to Open File in Reference Cell

fchiav

New Member
Joined
Feb 10, 2010
Messages
6
Hi,

I'm not skilled in VBA, so the following is created from Macro Recorder.

The macro below functions, though actions 422.csv which was the original file when recording the macro.
Rather, i'm wanting the macro to action the respective csv file for that same worksheet.

My data is saved in csv files (in same directory as workbook) with names nnn.csv. Each subsequent file is the next number in sequence.

Each worksheet references it respective csv data file in the cell AI17

AH14 contains a hyperlink to this respective csv file. It uses value in cell AI17 for link location. This hyperlink functions correctly by itself.

Thanking you in advance for your time & assistance on my query.

Code:
Sub Copy_Data()
'
' Copy_Data Macro
'


'
    Calculate
    Range("AH14").Select
    Workbooks.Open Filename:= _
        "C:\Tests\422.csv"
    ActiveWindow.Visible = False
    Windows("422.csv").Visible = True
    ActiveCell.SpecialCells(xlLastCell).Select
    Range(Selection, Cells(1)).Select
    Selection.Copy
    Windows("Test System.xlsm").Activate
    Range("B3").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    ActiveWorkbook.Worksheets("TS (422)").AutoFilter.Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("TS (422)").AutoFilter.Sort.SortFields.Add Key:= _
        Range("U3"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
        xlSortTextAsNumbers
    With ActiveWorkbook.Worksheets("TS (422)").AutoFilter.Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Calculate
    Range("AH41:AY41").Select
    Selection.Copy
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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