Complex Macro to fill in employees wages

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I'll try make this as clear as possible I realise its quite complex but hopefully someone can help.

Ok so I have a sheet called "Employees Details"
Column F are the Names
Column G are salary's

Now I have a sheet called Staff

In this sheet i work out their wages each month,
what i need is a macro that can look up each employees rate in "Employees Details" column G by matching their name (All names are unique)

The thing is the layout is not even so we are going to need to search for "Hourly Rate" as a header down column "C"

So if was doing this in english heres what i'd put

For each "Hourly Rate" in Column "C" look at name in cell above,

then goto "Employees Details" and find that name in column F, take the value in same row column G and put it next to the "Hourly Rate" in column D

I hope that makes sense?

please help if you can
thanks
Tony
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Could you put the structure of the Sheets for us, especially the structure of the Staff Sheet left a little unclear to me.

XL2BB or even a screenshot would help.
 
Upvote 0
Staff Sheet
ABCDE
HeadersThis is the row i want filled
Tony
Hourly RateFind This
Age
other data posssably blank cells
Jim
Hourly RateFind this etc!
So Column C has lots of headers, there is no sequence, I want to fill in everyones Hourly Rate in column DSo i need a macro to look down column C for the words "Hourly Rate"Goto "Employees Details" sheet,Find the name above Hourly Rate, in column FTake the rate in G and put it into D


Employee Details
DEFGH
NameHourly Rate
Jim
11
Sue21
Harry11
Tony25
mick15
Jim21
 
Upvote 0
How about
VBA Code:
Sub tonywatson()
   Dim Cl As Range
   Dim Dic As Object
   
   Set Dic = CreateObject("scripting.dictionary")
   With Sheets("Employees Details")
      For Each Cl In .Range("F2", .Range("F" & Rows.Count).End(xlUp))
         Dic(Cl.Value) = Cl.Offset(, 1).Value
      Next Cl
   End With
   With Sheets("Staff")
      With .Range("C2", .Range("C" & Rows.Count).End(xlUp))
         .Replace "Hourly Rate", "=xxxHourly Rate", xlWhole, , False, , False, False
         For Each Cl In .SpecialCells(xlFormulas, xlErrors)
            Cl.Offset(, 1).Value = Dic(Cl.Offset(-1).Value)
         Next Cl
         .Replace "=xxxHourly Rate", "Hourly Rate", xlWhole, , False, , False, False
      End With
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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