Use the address of a header cell to reference the range below it within a worksheetfunction.

Qazzart

New Member
Joined
Jul 11, 2014
Messages
9
Hi Everyone,

So Im stumped, and I have found no soulutions online as of yet.
Im using Excel 2010.

I recive a report that never has the headers in the same spot twice, so I cant reference them by cell.
I figured out how to reference the first unused column in the worksheet, then flood fill it with my formulas... as seen below:

Code:
sub test()

'....some code here.....

j = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Column + 1
i = ActiveSheet.UsedRange.Rows.Count

Set rngBackordered = ActiveSheet.UsedRange.Find("Backordered", , xlValues, xlWhole)
Backordered = rngBackordered.Offset(1, 0).Address(False, False)

Set rngLLTMat = ActiveSheet.UsedRange.Find("LLT Mat", , xlValues, xlWhole)
LLTMat = rngLLTMat.Offset(1, 0).Address(False, False)

Set rngInPurchase = ActiveSheet.UsedRange.Find("In Purchase", , xlValues, xlWhole)
InPurchase = rngInPurchase.Offset(1, 0).Address(False, False)

Cells(1, j).Value = "LLT Unawarded"
    With Range(Cells(2, j), Cells(i, j))
        .Formula = "=IF(OR(AND(" & LLTMat & "=""Yes""," & Backordered & "=""Yes""),AND(" & LLTMat & "=""Yes""," & InPurchase & "=""Yes"")),""Yes"",""No"")"
        .Value = .Value
    End With

'....some code here.....

end sub

what I want to do, is (for instance with LLTMat) do a Countif and assign that to a named cell.

Code:
[TotalLLTMat] = worksheetfuntion.CountIf(Range(), "Yes")

My question is, How do I reference the entire column when I only have the header address.

as always, Thank you all for your time and your help.

~Qazzart
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi Qazzart,

If you already have the range object for the found Header Cell, then you don't need to convert it to an address string to be used in a WorksheetFunction.

Instead use the object like:

To reference the entire column...
Code:
[TotalLLTMat] = WorksheetFunction.CountIf(rngLLTMat.EntireColumn, "Yes")

To reference all the cells in the column below the header...
Code:
With ActiveSheet
   Set rngLLTMat = .UsedRange.Find("LLT Mat", , xlValues, xlWhole)
   Set rngBelowLLTMat = Range(rngLLTMat(2), .Cells(.Rows.Count, rngLLTMat.Column))
End With

[TotalLLTMat] = WorksheetFunction.CountIf(rngBelowLLTMat, "Yes")


If all you had was the address string of a cell on the ActiveSheet but no range object, you could do something similar.

Code:
LLTMat = "K3"
[TotalLLTMat] = WorksheetFunction.CountIf(Range(LLTMat).EntireColumn, "Yes")
 
Upvote 0
Jerry,

Thank you so much for your help, it worked perfectly, also thank you for explaining the command so well.

~Qazzart
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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