How to get data from columns with headers using macros

Melzebu

New Member
Joined
Jan 24, 2022
Messages
8
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
Hi everyone,

I have a small question for you:

Let's say I have a table with headers and I'm trying to calculate an average.
I'm using the following macro to calculate it
Sub Average()
'
' Average Macro
'
'
ActiveCell.FormulaR1C1 = _
"=IFERROR(AVERAGEIF('Report'!C[-2],""Severity 1"",'Report'!C[3]),""-"")"
End Sub

but I would like to change 'Report'!C[-2] with the column header "Severity" and 'Report'!C[3] with the column header "FRT".
How can I do that? Are there some "universal" lines I can use in all macros where I need to get data from a specific column with header?

Thank you again for your help.
Cheers
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
for such basic things, i use the macro-recorder, do the handling and delete all unnecessary noise.
I did this for you and the result was this
ActiveCell.FormulaR1C1 = "=IFERROR(AVERAGEIF(Tabel1[MYA],""severity"",Tabel1[MYB]),""?"")"
so, the tablename and between squares the name of your header
 
Upvote 0
Solution
for such basic things, i use the macro-recorder, do the handling and delete all unnecessary noise.
I did this for you and the result was this
ActiveCell.FormulaR1C1 = "=IFERROR(AVERAGEIF(Tabel1[MYA],""severity"",Tabel1[MYB]),""?"")"
so, the tablename and between squares the name of your header
Thanks BSALV, that really did the work.
 
Upvote 0

Forum statistics

Threads
1,215,459
Messages
6,124,947
Members
449,198
Latest member
MhammadishaqKhan

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