Hello all!
As the title says, this is in regards to exporting data from a range of cells to a CSV file, named after a value in another cell and then a separate script to import the same data based on what value you have in aforementioned cell.
I’ve taken a screenshot with some pointers here, because I realise my explanation doesn’t really flesh it out enough:
Excel.PNG
1. This is the dropdown menu of stations that I’m evaluating. This value should be the name of the csv file (a unique csv file for every station, of course), so “2151.csv”, “2159.csv” etc etc.
2. These ranges are the ones I want to export/import. Not the “Totalt:” ranges, as these use formulas that add up previous values. (Maybe that’d be easier to include them as well? If it just copies in the same formula, nothing will be lost)
3. This is a Clear command, and I managed that on my own.
4. After I’ve cleared the cells, I would like to, depending on the value in the dropdown menu, be able to import the values from the csv file(s).
How far have I gotten myself? Not very far. I’ve done the Clear command, and I got hold of this which I’ve modified slightly:
My colleague who handles most of this type of work said it is entirely possible, but then talked about looping instead of just repeating my code, and when I tried inserting that, well the whole damn thing broke down, and that several of my code lines were unnecessary.Private Sub CommandButton2_Click()
Dim wb As Workbook
Dim saveFile As String
Dim WorkRng As Range
On Error Resume Next
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set WorkRng = Application.Range("E10:Q13")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wb = Application.Workbooks.Add
WorkRng.Copy
wb.Worksheets(1).Paste
saveFile = Application.GetSaveAsFilename(fileFilter:="Text Files (*.txt), *.txt")
wb.SaveAs filename:=saveFile, FileFormat:=xlText, CreateBackup:=False
wb.Close
Application.CutCopyMode = False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
So my need for help is this: first, is it really possible? Second, if anyone’s got the time, can you help me and if you don’t have the time, could you point me perhaps to what line of thought to pursue?
Three, I can provide a copy of the Excel file if you need it.
Bookmarks