Excel Function in VBA hidden rows

ajamr

New Member
Joined
Nov 19, 2017
Messages
3
Hi everyone,

I created a function in excel vba, saved it in the personal.xlsb, and it works exactly as I want it, the only problem is that it only works when I "unhide" the header row. I tried searching the problem but I couldn't find anything.

Example Table

[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]Header 1[/TD]
[TD]Header 2[/TD]
[TD]Header 3[/TD]
[/TR]
[TR]
[TD]Subitem 1[/TD]
[TD]1[/TD]
[TD]6[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]Subitem 2[/TD]
[TD]4[/TD]
[TD]3[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]Subitem 3[/TD]
[TD]1[/TD]
[TD]5[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]Subitem 4[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]3[/TD]
[/TR]
</tbody>[/TABLE]


The function code below...

Code:
Public Function BOQTakeOff(subitem As Range, header As Range)

Dim txt As String
For Each cell In subitem
If cell.Value > 0 Then
txt = txt & " " & cell.Value & " x " & Cells(header.Row, cell.Column).Value & "," & vbCrLf
End If
Next cell
BOQTakeOff = txt

End Function

The end result will be something like

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]1 x Header 1,
6 x Header 2,
[/TD]
[/TR]
[TR]
[TD]4 x Header 1,
3 x Header 2,
2 x Header 3,[/TD]
[/TR]
[TR]
[TD]1 x Header 1,
5 x Header 2,
[/TD]
[/TR]
[TR]
[TD]3 x Header 3,[/TD]
[/TR]
</tbody>[/TABLE]

The code works, perfectly, but only when I have to unhide the "header" row in my original table...

Really appreciate your help...
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
How are you using this function? From a macro, or from a sheet?
Using it in a sheet works for me

Excel 2013 32 bit
DEFGH
5
7Subitem 11601 x Header 1, 6 x Header 2,
8Subitem 2432
9Subitem 3150
10Subitem 4003
Test1
Cell Formulas
RangeFormula
H7=BOQTakeOff(E7:G7,E6:G6)
 
Upvote 0
I am reading this from a macro of the personal.xlsb file.
If I use it in the same workbook, it works without a flaw, however; when reading it as a macro from the personal.xlsb file, i have to un-hide the source table rows in order to make it work.
 
Upvote 0
a) What macro calls the function?
b) How is the header set in that macro?
 
Upvote 0
Your code working,
but I have to lock the header address, so the result are exactly like yours.

=PERSONAL.XLSB!BOQTakeOff(E2:G2,$E$1:$G$1)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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