Want to select a variable number of cells and enter values contained in their "connected" cells when clicking command button

tattie

New Member
Joined
Nov 28, 2008
Messages
1
Hi all

terrible Title I know but didn't know how better to explain it. It's actually very simple but unfortunately I am not yet good enough at this to work it out.

I have a "master table" set up with staff names in Column A and dates in Columns D - DF

Underneath I have the same staff names and dates, but with the rostered hours data in each relevant cell (i.e. per person / date).

What I am trying to do is have a command button that, when a cell or range of cells is highlighted in the "master" table, looks at the relevant date's rostered hours and enters this value in the master table.

So - e.g. Select F5 - click on button - macro looks up F325 and enters that value in F5.
Select H12 - M12 - click on button, macro looks up H332, I332, J332, K332....etc etc and enters those values in each relevant cell.

My current (extremely basic) code only picks up the first "connected cell" value and then duplicates this across the selected range. I know it's because I'm not using the correct keyword (i.e. ActiveCell) but don't know what do do instead.

Any help much appreciated as I am very stuck and short on time!!

Code:
Sub CommandButton1_Click()
'
' FullDayLeave Macro
' Inserts one day's full annual leave in the highlighted cell
' 
'
'
 
 
    With Selection.Interior
        .ColorIndex = 50
        .Pattern = xlSolid
    End With
    Selection.Font.ColorIndex = 50
    Selection.FormulaR1C1 = ActiveCell.Offset(302, 0)
 
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

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