Results 1 to 6 of 6

VB to use data from spreadsheet and input box to create new folder and text file

Threaded View

cmccabe VB to use data from... 08-19-2015, 02:34 PM
AlphaFrog Re: VB to use data from... 08-19-2015, 04:18 PM
cmccabe Re: VB to use data from... 08-19-2015, 04:48 PM
AlphaFrog Re: VB to use data from... 08-19-2015, 04:55 PM
cmccabe Re: VB to use data from... 08-19-2015, 05:18 PM
AlphaFrog Re: VB to use data from... 08-19-2015, 05:40 PM
  1. #1
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    VB to use data from spreadsheet and input box to create new folder and text file

    I am trying to write a VB that will use the data from an exsiting excel spreadsheet to create a new folder in a specific location (using an input prompt) and create a text file (using specific data on the spreadsheet and from the input prompt). Attached are an example of the spreadsheet and the desired output, and below is an attempt at a VB. Am I close to getting this to work? Thank you .

    VB
        Dim myBarcode As Variant     ' Enter Barcode
        Dim myScan As Variant        ' Enter ScanDate 
    myBarcode = InputBox("Please enter the barcode")
    myScan = InputBox("Please enter scan date")
         Range("B20").Value = myBarcode
         Range("B21").Value = myScan
    	 
         On Error Resume Next ' Create nexus directory and folder
         MkDir = "N:\1_DATA\MicroArray\NexusData\ActiveSheet.Range("B20").Value & "_" ActiveSheet.Range("B21").Value\"
    	 On Error Goto 0
    
        Dim sht As Worksheet     ' Create template based on name
        Dim sSave As String
        Dim fFN As String
    	Dim sFN As String
    	Dim tFN As String
    	Dim lFN As String
        Dim Directory As String
        Dim sText As Sting
    
    Set sht = ActiveSheet
        Beep
        sSave = MsgBox("The setup has been printed. " & _
               "Do you want to create a template for analysis now?", vbQuestion + vbYesNo)
    
    If sSave = vbYes Then
            
       		sText = "Experiment Sample	Control Sample	Display Name	Gender	Control Gender	SpikeIn	Location"
            fFN = ActiveSheet.Range("B20").Value & "_532Block1" & vbTab & ActiveSheet.Range("B20").Value & "_635Block1"	& " " & ActiveSheet.Range("B8").Value & " " & ActiveSheet.Range("B9").Value & vbTab & ActiveSheet.Range("B10").Value & vbTab & ActiveSheet.Range("B5").Value & vbTab & ActiveSheet.Range("B11").Value & vbTab & ActiveSheet.Range("B12").Value
            sFN = ActiveSheet.Range("B20").Value & "_532Block2" & vbTab & ActiveSheet.Range("B20").Value & "_635Block2"	& " " & ActiveSheet.Range("C8").Value & " " & ActiveSheet.Range("C9").Value & vbTab & ActiveSheet.Range("C10").Value & vbTab & ActiveSheet.Range("C5").Value & vbTab & ActiveSheet.Range("C11").Value & vbTab & ActiveSheet.Range("C12").Value
    		tFN = ActiveSheet.Range("B20").Value & "_532Block3" & vbTab & ActiveSheet.Range("B20").Value & "_635Block3"	& " " & ActiveSheet.Range("D8").Value & " " & ActiveSheet.Range("D9").Value & vbTab & ActiveSheet.Range("D10").Value & vbTab & ActiveSheet.Range("D5").Value & vbTab & ActiveSheet.Range("D11").Value & vbTab & ActiveSheet.Range("D12").Value
    		lFN = ActiveSheet.Range("B20").Value & "_532Block4" & vbTab & ActiveSheet.Range("B20").Value & "_635Block4"	& " " & ActiveSheet.Range("E8").Value & " " & ActiveSheet.Range("E9").Value & vbTab & ActiveSheet.Range("E10").Value & vbTab & ActiveSheet.Range("E5").Value & vbTab & ActiveSheet.Range("E11").Value & vbTab & ActiveSheet.Range("E12").Value
    		Directory = "N:\1_DATA\MicroArray\NexusData\ActiveSheet.Range("B20").Value & "_" ActiveSheet.Range("B21").Value\template.txt"
    		sht.Parent.SaveAs Filename:=Directory & fFN,sFN,tFN,lFN, FileFormat:=xlTextMSDOS
            Application.Quit
    
    Else
            MsgBox "A template has not been created, Goodbye!", vbExclamation
            Application.DisplayAlerts = False
            Application.Quit
            If sFN = "False" Then Exit Sub
        End If
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. how to create a button that print out a file that data matched the input window
    By nan342 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-15-2013, 04:20 PM
  2. [SOLVED] Macro to copy file names and data from each file in a folder into master spreadsheet
    By dee1989 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-10-2012, 05:52 AM
  3. Replies: 3
    Last Post: 09-30-2011, 04:35 AM
  4. Save a file to a folder, create folder if it doesn't exist
    By mcinnes01 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-01-2010, 09:12 AM
  5. Create Folder with system date then save file to folder
    By cartotech81 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2009, 02:12 PM
  6. How to input data from a text file?
    By jp001 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-08-2009, 10:23 AM
  7. Replies: 6
    Last Post: 08-11-2006, 03:41 PM
  8. Import text file and create new spreadsheet
    By demianill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-23-2006, 02:25 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