+ Reply to Thread
Results 1 to 9 of 9

Using VBA for formulas in sheet

  1. #1
    Registered User
    Join Date
    01-20-2022
    Location
    Overland Park, KS
    MS-Off Ver
    365
    Posts
    8

    Post Using VBA for formulas in sheet

    I am having an issue with the attached sheet. I have equations in column D, F and K. I need assistance with VBA code to do the calculations so that there are not formulas in the cells. Is this possible to do with these three columns?

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Using VBA for formulas in sheet

    Try:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    01-20-2022
    Location
    Overland Park, KS
    MS-Off Ver
    365
    Posts
    8

    Re: Using VBA for formulas in sheet

    Is there a way to do this without it being a macro. For example right now when the date is changed in B2 column D auto populates the date that is in B2. When the name in column G changes column F auto changes the code and when the times in column H & I are changes Column K total hours changes. Can this be done with VBA or does it have to be a macro that the user has to initiate when a change is made. I hope that makes sense.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Using VBA for formulas in sheet

    A macro IS VBA. You can use a Worksheet Change Event handler to monitor column G and, when it changes, either drop the formulae in and convert them to values (effectively what the macro does) or evaluate the formulae internally.

    If columns H and I are manually changed and column K depends on them, then they need to be monitored too.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Using VBA for formulas in sheet

    Try:
    Please Login or Register  to view this content.

  6. #6
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Using VBA for formulas in sheet

    Or try worksheet_Change even:

    PHP Code: 
    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Lr&, f
    Lr 
    Cells(Rows.Count"G").End(xlUp).Row
        
    'If any value in B2, column G,H,I change then update
        If Not Intersect(Target, Range("B2")) Is Nothing Or Not Intersect(Target, Range("G4:G" & Lr)) Is Nothing _
        Or Not Intersect(Target, Range("H4:H" & Lr)) Is Nothing Or Not Intersect(Target, Range("I4:I" & Lr)) Is Nothing Then
            For Each cell In Range("D4:D" & Lr)
                cell.Value = Range("B2").Value ' 
    update column D with date in cell B2
                cell
    .Offset(07).Value cell.Offset(05).Value cell.Offset(04).Value ' update total hour
                ' 
    vlookup EE code update
                With Sheets
    ("Employee Master")
                    
    Set f = .Range("A1:A" & .Cells(Rows.Count"A").End(xlUp).Row).Find(cell.Offset(03).Value' loop thru name list
                    If f Is Nothing Then
                        cell.Offset(0, 2).Value = "" ' 
    if vlookup failed, return blank cell
                    
    Else
                        
    cell.Offset(02).Value f.Offset(01' return EE code
                    End If
                End With
            Next
        End If
    End Sub 
    Quang PT

  7. #7
    Registered User
    Join Date
    01-20-2022
    Location
    Overland Park, KS
    MS-Off Ver
    365
    Posts
    8

    Re: Using VBA for formulas in sheet

    I would like to know if code could be provided that will open a vba user form when the file is opened that will fill in cell B1 with the name and B2 with the date. I would like the user to have to fill in a user form with data that will than input the data into these cells. I hope this makes sense.

  8. #8
    Registered User
    Join Date
    01-20-2022
    Location
    Overland Park, KS
    MS-Off Ver
    365
    Posts
    8

    Re: Using VBA for formulas in sheet

    Can I also ask how I would make the user required to fill in the information before they can use the file?

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Using VBA for formulas in sheet

    I would like to know if code could be provided that will open a vba user form when the file is opened that will fill in cell B1 with the name and B2 with the date. I would like the user to have to fill in a user form with data that will than input the data into these cells. I hope this makes sense.
    Can I also ask how I would make the user required to fill in the information before they can use the file?
    Your question has been answered. Please mark it as solved. This is a new question and rider. Please start a new thread. Provide a link back to this thread for background.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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. Copy Formulas from 'Formulas' Sheet into Data Table Columns
    By Jonny757 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-10-2020, 08:18 PM
  2. Replies: 3
    Last Post: 02-18-2020, 02:01 PM
  3. [SOLVED] VBA to copy master sheet and insert new line on summary sheet with updated formulas
    By Scott 2020 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-11-2020, 11:06 AM
  4. VBA Code - Copy Table in Excel from Sheet to Sheet - Values Only (No formulas)
    By Laurunner in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-10-2019, 08:51 AM
  5. Replies: 5
    Last Post: 03-03-2018, 01:16 AM
  6. Replies: 3
    Last Post: 05-25-2011, 01:30 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