Complex Macro to fill in employees wages

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
2,865
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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Tupe77

Board Regular
Joined
Nov 26, 2020
Messages
112
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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.
 

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
2,865
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
63,974
Office Version
  1. 365
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
63,974
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Forum statistics

Threads
1,144,339
Messages
5,723,800
Members
422,517
Latest member
VisioExcel

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
Top