Results 1 to 4 of 4

Copy Paste Data String here if found or there if not - Help a noob please

Threaded View

  1. #1
    Registered User
    Join Date
    01-17-2019
    Location
    Melbourne Australia
    MS-Off Ver
    2016
    Posts
    10

    Copy Paste Data String here if found or there if not - Help a noob please

    Greetings,
    I am working on a basic job record that can go from quote to finished job and have created a string to store all the relevant reporting data on its own sheet within the file.

    My thought is that various people will be able to create or update the job file and save it, while one expert would go into any files changed during the day and save those changes to a database.

    This is trying to use Excel instead of a integrated relational database package that would probably do a better job than my hack - this is more fun!

    So the first part is just to save the file and this seems to be working OK (but maybe you could point out redundant code in this) (The job number resides at B7)

     Sub SaveJob()
    '
    ' SaveJob Macro
    ' First part of File Saving
    '
    
    '
    Sheets("Mock Quote Master").Select
        ChDir "C:\Users\Albert15\Documents\LTP files\DevWork\Quotes"
        Range("B7").Select
        Selection.Copy
        Application.CutCopyMode = False
        
        Dim FName           As String
        Dim FPath           As String
         
        FPath = "C:\Users\Albert15\Documents\LTP files\DevWork\Quotes"
        FName = Sheets("Mock Quote Master").Range("b7").Text
        ThisWorkbook.SaveAs Filename:=FPath & "\" & FName & ".xlsm"
        FileFormat = xlOpenXMLWorkbookMacroEnabled
    End Sub
    For writing to the database there are 2 scenarios - (A) It's an existing job that has been updated, it will already have an entry in the database (the job ref will be found in the column) and therefore the database will get more information at an existing line.
    or (B) it's a new entry and I would like to write the data the the blank line below the last database entry. (I have called both PastePoint in the code below) The key and first cell of the database line is the same job reference as the saved job file.

    Here I have tried to mimic some of the similar things I've read here but it's failing badly with my lack of VBA coding knowledge.. This is my attempt...

     Sub SaveString()
    '
    ' SaveString Macro
    ' First tests - Reporting Database must be open in background
    '
    
    '
    Sheets("Mock Quote Master").Select
        Range("B7").Select
        Selection.CopyApplication.CutCopyMode = False
        
        Dim FName          As String
        Dim FPath           As String
        Dim QRef           As String
        
        FPath = "C:\Users\Albert15\Documents\LTP files\DevWork\Quotes"
        FName = Sheets("Mock Quote Master").Range("b7").Text
        QRef = Sheets("Mock Quote Master").Range("b7").Text
        Windows("Job Reporting Database.xlsx").Activate
        Sheets("Database").Select
        Columns("A:A").Select
        Set PastePoint = Cells.Find(What = "Qref")
        If Find Is Nothing Then
        Range("A4").Select
        Set PastePoint = Range(Selection, Selection.End(xlDown).Offset(1, 0)).Select
        Windows(FPath & "\" & FName & ".xlsm").Activate
        Application.WindowState = xlNormal
        Sheets("Data String").Select
        Range("A7:AI7").Select
        Selection.Copy
        Range("A8").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Range("A8:A18").Select
        Application.CutCopyMode = False
        Selection.Copy
        Windows("Job Reporting Database.xlsx").Activate
        GoTo PastePoint
        Selection.Paste
        ActiveWorkbook.Save
        ActiveWindow.Close
    End Sub
    Thank you
    Last edited by Albert Toet; 01-20-2019 at 04:12 AM. Reason: Clarify reason for finding in column

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Copy data from text file after a particular string is found
    By chandrup23 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-22-2016, 06:27 AM
  2. string macro for a user input button, copy and paste data from all sheets to summary
    By Lawleypops in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-15-2015, 11:17 AM
  3. string macro for a user input button, copy and paste data from all sheets to summary
    By Lawleypops in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-14-2015, 11:09 PM
  4. Replies: 14
    Last Post: 07-29-2013, 05:41 PM
  5. [SOLVED] Compare two columns and copy and paste data from a third column when a match is found
    By GatorsBucs in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-28-2013, 06:54 PM
  6. Macro to Copy/Paste Cells if Data is found with Filter
    By CMPidgeon in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-16-2012, 04:05 PM
  7. [SOLVED] How to paste data from one sheet onto another (noob question, I know, but plz help!!)
    By OliveMarie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-23-2012, 11:15 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