VBA to post values via cell address value in worksheet

Derick63

Board Regular
Joined
Apr 6, 2018
Messages
71
Hello everyone,
I created a Payroll Workbook and was just about to complete it when I realized I wanted to include a Corrections worksheet because I don't want the user to go into sensitive worksheets and mess with data they shouldn't be accessing.

So here's my scenario:
In my Corrections worksheet;
1574272881566.png

A5:F5 - Formulas to retrieve existing data from any of 12 sheets with two criteria (Name & Date)
A6:F6 - Cells to replace the existing data (User Entry)
A7:F7 - Formula to retrieve and display cell address for each value in A5:F5 using two criteria (Name & Date). These cells, A7:F7, are hidden by Format ";;;"

I started to create a module to Update the data by declaring variables for each value of new data (A6:F6) and each of the cell addresses (A7:F7). I don't know how to get the new data into the cell using the cell address variable.
VBA Code:
Sub Update()

' The GoTO***** Variables below are taken from Worksheet Corrections Range A7:F7 where a formula
' exists to retrieve the cell address from which the data in A5:F5 resides.
' Worksheet Corrections A6:F6 is the data to replace A5:F5

Dim HrsWkd, HlyDy, BnsCom, Loan, VacBal, SickBal As Integer
Dim GoToHrsWkd, GoToHlyDy, GoToBnsCom, GoToLoan, GoToVacBal, GoToSickBal As String

    
        HrsWkd = Sheets("Corrections").Range("A6").Value   'New Hours
        GoToHrsWkd = Sheets("Corrections").Range("A7")     'Where New Hours will be placed
    
        HlyDy = Sheets("Corrections").Range("B6").Value    'New Holiday Hours
        GoToHlyDy = Sheets("Corrections").Range("B7")      'Where New Holiday Hours will be placed
    
        BnsCom = Sheets("Corrections").Range("C6").Value   'New Bonus/Commissions
        GoToBnsCom = Sheets("Corrections").Range("C7")     'Where New Bonus/Commissions will be placed
    
        Loan = Sheets("Corrections").Range("D6").Value     'New Loan Balance
        GoToLoan = Sheets("Corrections").Range("D7")       'Where New Loan Balance will be placed
    
        VacBal = Sheets("Corrections").Range("E6").Value   'New Vacation Days Balance
        GoToVacBal = Sheets("Corrections").Range("E7")     'Where New Vacation Days Balance will be placed
    
        SickBal = Sheets("Corrections").Range("F6").Value  'New Sick Days Balance
        GoToSickBal = Sheets("Corrections").Range("F7")    'Where New Sick Days Balance will be placed
    
End Sub

Being such a Noob, I tried to figure it out via VBA and wiped out some formulas on the Corrections worksheet and had to start over. Thank goodness for back-ups.
I created a stripped down version of the workbook to include here but XL2BB won't work because the formulas have arrays in them so I have it here on Google Drive Google Drive file location if you want to take a look at it.

Any help would be an education on my part and much appreciated. Thanks!

Derick
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
If anyone wants to know how I got the Employee's name from the Drop Down List (cell B2) into the macro run button; It'll change when B2 changes
  • Select the shape
  • In the formula bar, type equal sign (=) then choose the cell, in this case $B$2
  • Select the Shape again
  • Move the cursor with the left and/or right keys respectively to type your prefix and suffix
 
Upvote 0
I solved it! Thanks!
VBA Code:
Sub Update()

' The GoTO***** Variables below are taken from Worksheet Corrections Range A7:F7 where a formula
' exists to retrieve the cell address from which the data in A5:F5 resides.
' Worksheet Corrections A6:F6 is the data to replace A5:F5

Dim HrsWkd, HlyDy, BnsCom, Loan, VacBal, SickBal As Integer
Dim GoToHrsWkd, GoToHlyDy, GoToBnsCom, GoToLoan, GoToVacBal, GoToSickBal As String

    
    HrsWkd = Sheets("Corrections").Range("A6").Value   'New Hours
    GoToHrsWkd = Sheets("Corrections").Range("A7")     'Where New Hours will be placed
    Range(GoToHrsWkd) = HrsWkd
    
    HlyDy = Sheets("Corrections").Range("B6").Value    'New Holiday Hours
    GoToHlyDy = Sheets("Corrections").Range("B7")      'Where New Holiday Hours will be placed
    Range(GoToHlyDy) = HlyDy
    
    BnsCom = Sheets("Corrections").Range("C6").Value   'New Bonus/Commissions
    GoToBnsCom = Sheets("Corrections").Range("C7")     'Where New Bonus/Commissions will be placed
    Range(GoToBnsCom) = BnsCom
    
    Loan = Sheets("Corrections").Range("D6").Value     'New Loan Balance
    GoToLoan = Sheets("Corrections").Range("D7")       'Where New Loan Balance will be placed
    Range(GoToLoan) = Loan
    
    VacBal = Sheets("Corrections").Range("E6").Value   'New Vacation Days Balance
    GoToVacBal = Sheets("Corrections").Range("E7")     'Where New Vacation Days Balance will be placed
    Range(GoToVacBal) = VacBal
    
    SickBal = Sheets("Corrections").Range("F6").Value  'New Sick Days Balance
    GoToSickBal = Sheets("Corrections").Range("F7")    'Where New Sick Days Balance will be placed
    Range(GoToSickBal) = SickBal

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,942
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top