+ Reply to Thread
Results 1 to 3 of 3

Exporting range of cell based on Cell Value and Importing

  1. #1
    Registered User
    Join Date
    08-07-2019
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    2

    Exporting range of cell based on Cell Value and Importing

    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:

    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
    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.

    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.

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Exporting range of cell based on Cell Value and Importing

    Yes, it's possible... please publish a copy of your excel file and of one csv file.
    Do you need to loop exporting all stations?

    Regards,
    Antonio

  3. #3
    Registered User
    Join Date
    08-07-2019
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    2

    Re: Exporting range of cell based on Cell Value and Importing

    Hi Antonio!

    Will do. I tossed in some extra csv files to show you how they turn out. The one named "2151.csv" was named so manually.
    Hm, no, I don't think so. When I hit "export", I only want to export the current station.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Importing-Exporting
    By Richard Mahan in forum Excel General
    Replies: 3
    Last Post: 02-15-2019, 12:58 AM
  2. Exporting/Importing Multicell Named Range Values
    By shoulddt in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-25-2016, 02:28 AM
  3. importing exporting xml
    By jrtaylor in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-04-2011, 02:19 PM
  4. Replies: 2
    Last Post: 11-20-2009, 02:05 PM
  5. Importing Data From another workbook based on cell content
    By xxchrisukxx in forum Excel General
    Replies: 1
    Last Post: 08-16-2007, 06:44 AM
  6. [SOLVED] Importing each cell in a range to a different worksheet
    By Insp Gadget in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-08-2006, 05:55 AM
  7. Cell Limitations ? Formatting and Size when exporting to Tab based Text file?
    By PaulH_1980 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-15-2006, 07:51 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1