Results 1 to 7 of 7

Insert or copy formulas using VBA

Threaded View

  1. #1
    Registered User
    Join Date
    05-14-2014
    MS-Off Ver
    Excel 2013
    Posts
    14

    Insert or copy formulas using VBA

    Hello everyone,
    I am a novice at VBA and macros, but I've gone far using this great forum and a lot of trial and error until now.
    I'm currently stumped on how to insert a formula using a VBA routine. I have a userform that collects information and a SaveButtonClick() that transfers and the userform data to several cells in column's 1,5 thru 16 in a "data" sheet. However, cells in columns 2,3 & 4 in the data sheet required a vlookup formula and I hoped that adding the formula to the "transfer" syntax in the routine would work. I'm not sure if this method is the best, or if a copy/paste syntax would be more appropriate to insert formulas. Also, the vlookup's lookup_value has to come from the formula's active row (the row it was just copied to), specifically, column 1 or A.

    Warm wishes and many thanks on any help you can give!

    ____________________
    Private Sub Savebutton_click()
    
    Dim emptyRow As Long
    
    'Make Data Sheet active
    Sheets("Data").Activate
    emptyRow = WorksheetFunction.CountA(Range("A:A")) + 2
    
    'Transfer information
    Cells(emptyRow, 1).Value = StoreNo.Value
    'Cells(emptyRow, 2).Formula = "=VLOOKUP($A???,'Master Store List'!$A$3:$Q$4000,5))"
    'Cells(emptyRow, 3).Formula = "=VLOOKUP($A???,'Master Store List'!$A$3:$Q$4000,17))"
    'Cells(emptyRow, 4).Formula = "=VLOOKUP($A???,'Master Store List'!$A$3:$Q$4000,4))"
    Cells(emptyRow, 5).Value = ServiceDate.Value
    Cells(emptyRow, 6).Value = StartReg.Value
    Cells(emptyRow, 7).Value = StartSF.Value
    Cells(emptyRow, 8).Value = SalesReg.Value
    Cells(emptyRow, 9).Value = SalesSF.Value
    Cells(emptyRow, 10).Value = InvoiceNo.Value
    Cells(emptyRow, 11).Value = ReplaceReg.Value
    Cells(emptyRow, 12).Value = ReplaceSF.Value
    Cells(emptyRow, 17).Value = Comments.Value
    
    If DisplayCheckBox.Value = True Then Cells(emptyRow, 13).Value = Cells(emptyRow, 13).Value & "X"
    
    If ColdBoxCheckBox.Value = True Then Cells(emptyRow, 14).Value = Cells(emptyRow, 14).Value & "X"
    
    If InSchematicCheckBox.Value = True Then Cells(emptyRow, 15).Value = Cells(emptyRow, 15).Value & "X"
    
    If OtherCheckBox.Value = True Then Cells(emptyRow, 16).Value = Cells(emptyRow, 16).Value & "X"
    
    End Sub
    Last edited by Leith Ross; 05-16-2014 at 08:18 PM. Reason: Added Code Tags

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Insert rows and copy formulas
    By amlal in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-30-2012, 02:53 PM
  2. Insert a new row and copy all formulas down
    By treva26 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-17-2007, 06:12 PM
  3. insert row, copy formulas, have code example (I think).
    By gobbolino in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-14-2007, 12:10 AM
  4. Macro to insert copy and insert formulas only to next blank row
    By bob in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-30-2006, 07:10 AM
  5. [SOLVED] Copy/Insert rows with formulas
    By GregR in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-26-2005, 06:06 PM

Tags for this Thread

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