0% found this document useful (0 votes)
621 views12 pages

VBA For MEP Calculations

VBA for MEP

Uploaded by

yarzar172040
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
621 views12 pages

VBA For MEP Calculations

VBA for MEP

Uploaded by

yarzar172040
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

0

More

Next Blog

Tuesday, June 23, 2009

Create Blog

Download Zawgyi-One Font

VBA for MEP Calculations


Application
Programming
VBA (Visual
Basics for Application) Engineering Formula Functions
spread sheet (Microsoft Excel) VBA MS Offices Web
Script AutoCad
programming AutoCad

Content ()

AutoLisp, vBA, Diesel, Script programming process CAD & Design Tools
Trial and error Loop

Singapore: M&E and AutoCAD


Revit MEP 2010

MEP Systems
M&E Systems vs Buildings

Contents
I. Basic of Programming
II. VBA for Excel
III. Developing Programming Flowcharts for HVAC Air-Side Circular Duct Sizing Calculations (SI
Units)
IV. VBA Codes for Air Duct (SI Units)
V. Screenshots: Adding VBA Codes in Excel
VI. Screenshots: Use of VBA Functions in Excel Worksheet
VII. Html Color Coding by VBA
VIII. References

M&E Systems
Scope of M&E Systems
M&E:

M&E Architectural
M&E
M&E Design: High-Rise Buildings
Testing & Commissioning Process

HVAC
HVAC: Introduction to Design
HVAC: Building in Hot & Humid Climate
M&E Basics: Pipe & Duct Sizing
HVAC: Duct Sizing with VBA
HVAC: Duct Sizing

I. Basic of Programming
Programming Languages Detail basic instructions Languages

Automatic Control Systems


HVAC Control (01) : FCU



input: Get data from the keyboard, a file, or some other device.
output: Display data on the screen or send data to a file or other device.

Plumbing
Sanitary Plumbing: Introduction

Math / Operation : Perform basic mathematical operations like addition and multiplication.
conditional execution: Check for certain conditions and execute the appropriate sequence of
statements.
repetition: Perform some action repeatedly, usually with some variation.

Domestic Water Supply: Introduction


Water Tanks ( )

Algorithm (or) Pseudocode and Program Flow Chart Modular


programming Program

debug

Swimming Pools
Swimming Pools ( )

Program Planning

Debugging
Crush

Fire Protection
Fire Protection : Introduction

Programming Flowchart http://www.nos.org/htm/basic2.htm


Smoke Control: Pressurization Systems

Fire Sprinkler (Wet) System, S'pore

Start / End : (Programming


(Start) (End) )


Process : Computational steps or processing function of a program
Decision Making and Branching

...Back to Top ....

II. VBA for Excel


Excel VBA Application

Electrical
Electrical Power Distribution

Sustainable, Green and Environment


Green Buildings: USGBC's LEED/
S'pore GreenMark
Understanding LEED

VB for Application

Green Energy

VB for Excel Application

Clean Air:
Clean Water:

Sign In

Files (personal.xls or add-in ".xla", Newer version ".xlsx")


Excel VBA Object Model: Excel, Word, AutoCad VBA Applications
Object
Model

VBA

Macro Security

Engineering Exams
USA: EIT and FE Exam
------------------------------------

Function and Sub: Sub macro run processes Recently Updated


modify macro record
Form
HVAC: Duct Sizing with VBA
Graphical User Interface
Sub Excel Spread

Swimming Pools ( )

Sheet
Function Insert Function
-----------------------------------...Back to Top ....

III. Developing Programming Flowcharts for HVAC Air-Side Circular Duct Sizing Calculations (SI Units)
Cold Air Standard Duct Pressure Loss
Duct Pressure Loss 5%

Conditions
Temperature: 5 to 35 C

mail me: [email protected]

Please consider the environment before printing.

Labels

Elevation: 0 to 500m

AutoCAD (1)

Duct Pressure: -5 to 5 kPa relative to ambient pressure

CAD (2)


HVAC

Control (2)

Constraints

Velocity Friction Loss Duct Size Velocity

Electrical (1)

Environment (8)

Velocity Limits Basic Duct Sizing Consideration M&E Basics: Pipe & Duct Sizing

Fire Protection (5)

(
Ducting Piping )

General (1)

Circular Duct Size Function

HVAC (10)

Calculation Formulae ASHRAE Handbook: Fundamental

MEP Design (7)


MEP Systems (12)
Myanmar (2)
Sanitary (1)
Singapore (3)
Swimming Pools (1)
Testing and Commissioning (1)
USA-EIT/PE (1)
VBA (1)
Water Supply (4)

About Me
View my complete profile

Velocity Duct Size


Duct Size Pressure Loss
Limit



Limit
Pressure Loss Limit Duct Size

Function Functions
Functions


i. DuctSize_Cir_mm : Circular Duct Size
ii. DuctFrictionLoss_Pa: Circular Duct Frictioin Loss
iii. f_Colebrook: Colebrook's Friction Factor
Flowcharts
i. DuctSize_Cir_mm

ii. DuctFrictionLoss_Pa

iii. f_Colebrook

Circular Duct Duct Equivalent Circular Duct


HVAC Air-Side

Air Duct Conversion Formula

Conversion Formula VBA Code



Numerical Programming VBA Code Excel Visual Basic
Editor
".xla" Excel
XLStart Folder

personal.xls File

VBA Macro Security Level Powerful Operation Macro
Security

"personal.xls"
Record New Macro


Stop Macro
Visual Basic Editor "personal.xls"


Excel 2003 Excel 2007 Screenshots
...Back to Top ....

IV. VBA Codes for Air Duct (SI Units)


Air Duct Sizing
VBA Functions
Functions
1. DuctSize_Cir_mm(Air_cmh, Optional dP_Pa = 1, Optional V_mps = 8, Optional e_mm = 0.09)
Circular Duct Size
2. DuctFrictionLoss_Pa(Air_cmh, DuctDia_mm, Optional e_mm = 0.09)
Circular Duct Frictioin Loss
3. f_Colebrook(e_by_D, Re)
Colebrook's Friction Factor
4. DuctR2C(dH, dW)
Rectangular Duct Equivalent Circular Duct Diameter
Function
5. DuctO2C(dH, dW)
Oval Duct Equivalent Circular Duct Diameter
Function
6. DuctC2R(dD, Optional dH = 0)
Circular Duct Equivalent Rectangular Duct Dimension
Function
dH=0 Square Duct

7. DuctC2O_Width(dD, Optional dH = 0)
Circular Duct Equivalent Oval Duct Dimension
Function dH=0

Square duct round Duct


( ie, a = 2 * b )
8. Function DuctAirFlow_Cir_cmh(dD_mm, Optional dP_Pa = 1, Optional dV_mps = 9, Optional
e_mm = 0.09)
Circular Duct Allowable Air Flow (cmh)
9. DuctAirFlow_Rec_cmh(dW_mm, dH_mm, Optional dP_Pa = 1, Optional dV_mps = 9, Optional
e_mm = 0.09)
Rectangular Duct Allowable Air Flow (cmh)
10. DuctAirFlow_Oval_cmh(dW_mm, dH_mm, Optional dP_Pa = 1, Optional dV_mps = 9, Optional
e_mm = 0.09)
Oval Duct Allowable Air Flow (cmh)
Visual Basic Editor VBAProject(PERSONAL.XLS)
Module

e.g. AirDuct Code


VBA Codes Copy &
Paste (Screenshots: No.2
)

'General Section Declaration


Option Base 0 'array base
Option Compare Text
Private Const atm As Double = 101.325 ' Atmospheric pressure in kPA
Public Const pi As Double = 3.14159265358979

'Function No. 01: to calculate Circular Duct Size


Function DuctSize_Cir_mm(Air_cmh, Optional dP_Pa = 1, Optional V_mps = 8, Optional e_mm = 0.09)
'Calculate Circular Duct Size, Default for 1Pa/m, 8 m/s and Medium Surface Roughness 0.09mm
Dim dV As Double, dD As Double, dA As Double
Dim dP As Double
'calc Area which satisfy the velocity limits
dV = V_mps
dA = Air_cmh / (3600# * dV)
dD = (4 * dA / pi) ^ 0.5 * 1000
'call function for Friction Loss
dP = DuctFrictionLoss_Pa(Air_cmh, dD, e_mm)
If dP > dP_Pa Then
Do
'Use Power rule estimation for iteration
dD = dD * (dP / dP_Pa) ^ 0.25
dP = DuctFrictionLoss_Pa(Air_cmh, dD, e_mm)
'exit error 1%
If Abs((dP - dP_Pa) / dP_Pa) < 0.01 Then Exit Do
Loop
End If
DuctSize_Cir_mm = dD
End Function

'Function No. 02: to calculate duct friction loss


Function DuctFrictionLoss_Pa(Air_cmh, DuctDia_mm, Optional e_mm = 0.09)
'Calculate Friction Loss
Dim dQ As Double, dD As Double 'flowrate (m3/s), diameter(mm)
Dim dV As Double, dF As Double 'velocity (m/s), friction factor
Dim dM As Double, dE As Double 'density (kg/m3), surface roughness
Dim Re As Double, dA As Double
'For Cold Air Standard at density=1.2kg/m3
If Air_cmh * DuctDia_mm > 0 Then

dQ = Air_cmh / 3600# 'convert air flowrate to m3/s


dD = DuctDia_mm
dM = 1.2 'kg/m3 for cold air std
dA = 0.25 * pi * (dD / 1000#) ^ 2
dV = dQ / dA 'v=Q/A
Re = 66.4 * dD * dV 'Ref ASHRAE: or use Re = V * d / nu
dF = f_Colebrook(e_mm / dD, Re)
DuctFrictionLoss_Pa = 500 * dF * dM * dV * dV / dD
Else
DuctFrictionLoss_Pa = 0
End If
End Function

'Function No. 03: to calculate Colebrook Friction Factor


Function f_Colebrook(e_by_D, Re) 'e_by_D Relative roughness; Dh: Hydraulic Dia, Re: Reynold number
'Calculate Colebrook friction Factor
Dim f As Double, root_f As Double, root_f1 As Double
'Start with Tsal's estimation
f = 0.11 * (e_by_D + 68 / Re) ^ 0.25
If f < 0.018 Then
f = 0.85 * f + 0.0028
End If
root_f = f ^ 0.5
Do
root_f1 = -0.5 * Log(10) / Log(e_by_D / 3.7 + 2.51 / (root_f * Re))
'check if error is less than 0.5%
If Abs((root_f1 - root_f) / root_f) < 0.005 Then Exit Do
root_f = 0.5 * (root_f + root_f1) 'Use binary approach iteration
Loop
f_Colebrook = root_f ^ 2
End Function

'Function No. 04: Equivalent Circular Duct Size of a Rectangular Duct


Function DuctR2C(dH, dW) As Double
'Rectangular Duct to Circular Duct
If dW * dH > 0 Then
DuctR2C = 1.3 * ((dH * dW) ^ 0.625) / ((dH + dW) ^ 0.25)
Else
DuctR2C = 0
End If
End Function

'Function No. 05: Equivalent Circular Duct Size of an Oval Duct


Function DuctO2C(dH, dW) As Double
'Oval Duct to Circular Duct
Dim dA As Double, P As Double
If dW * dH > 0 Then
dA = (pi * dH ^ 2 / 4) + dH * (dW - dH)
P = pi * dH + 2 * (dW - dH)
DuctO2C = 1.55 * (dA ^ 0.625) / (P ^ 0.25)
Else
DuctO2C = 0
End If
End Function

'Function No. 06: Equivalent Rectangular Duct Dimension of a Circular Duct

Function DuctC2R(dD, Optional dH = 0) As Double


'Circular Duct to Rectangular Duct
'if Dimension (dH) is zero, square duct
'dH could be either dimension: "Width" or "Height"
Dim dW As Double, dW1 As Double
Dim dD1 As Double
If dH > 0 Then
'Estimate dH
dW = 0.25 * pi * dD * dD / dH
Do
dD1 = 1.3 * ((dH * dW) ^ 0.625) / ((dH + dW) ^ 0.25)
dW = dW * (dD / dD1) ^ 2
If Abs((dD1 - dD) / dD) < 0.005 Then Exit Do
Loop
Else
dW = dD * 0.9148
End If
DuctC2R = dW
End Function

'Function No. 07: Equivalent Oval Duct Dimension of a Circular Duct


Function DuctC2O_Width(dD, Optional dH = 0) As Double
'Circular Duct to Rectangular Duct
'if Dimension (dH) is zero, square duct + round, ie, a = 2 * b
'dH is dimension b for "Height", dW is dimension a for "Width"
'As nature, dH < dD
Dim dW As Double, dW1 As Double
Dim dD1 As Double
Dim dA As Double, P As Double
If dH > 0 Then
'Estimate dH
dW = 0.25 * pi * (dD * dD - dH * dH) / dH
Do
dA = (pi * dH ^ 2 / 4) + dH * (dW - dH)
P = pi * dH + 2 * (dW - dH)
dD1 = 1.55 * (dA ^ 0.625) / (P ^ 0.25)
dW = dW * (dD / dD1) ^ 2
If Abs((dD1 - dD) / dD) < 0.005 Then Exit Do
Loop
Else
dW = dD / 1.5234
End If
DuctC2O_Width = dW
End Function

'Function No. 08: To Calculate Allowable Air Flow from a Circular Duct.
Function DuctAirFlow_Cir_cmh(dD_mm, Optional dP_Pa = 1, Optional dV_mps = 9, Optional e_mm = 0.09)
Dim cmh As Double, dP As Double
Dim dD As Double, dV As Double
dV = dV_mps
dD = dD_mm
cmh = 0.0009 * pi * dD * dD * dV '0.0009 <- 0.25*3600/1000000
dP = DuctFrictionLoss_Pa(cmh, dD, e_mm)
If dP > dP_Pa Then
Do
dV = dV * (dP_Pa / dP) ^ 0.5
cmh = 0.0009 * pi * dD * dD * dV
dP = DuctFrictionLoss_Pa(cmh, dD, e_mm)

If Abs(dP - dP_Pa) / dP_Pa < 0.01 Then Exit Do


Loop
End If
DuctAirFlow_Cir_cmh = cmh
End Function

'Function No. 09: To Calculate Allowable Air Flow from a Rectangular Duct.
Function DuctAirFlow_Rec_cmh(dW_mm, dH_mm, Optional dP_Pa = 1, Optional dV_mps = 9, Optional
e_mm = 0.09)
Dim dD As Double, dV As Double
dV = dV_mps
dD = DuctR2C(dW_mm, dH_mm)
DuctAirFlow_Rec_cmh = DuctAirFlow_Cir_cmh(dD, dP_Pa, dV_mps, e_mm)
End Function

'Function No. 10: To Calculate Allowable Air Flow from an Oval Duct.
Function DuctAirFlow_Oval_cmh(dW_mm, dH_mm, Optional dP_Pa = 1, Optional dV_mps = 9, Optional
e_mm = 0.09)
Dim dD As Double, dV As Double
dV = dV_mps
dD = DuctO2C(dW_mm, dH_mm)
DuctAirFlow_Oval_cmh = DuctAirFlow_Cir_cmh(dD, dP_Pa, dV_mps, e_mm)
End Function

...Back to Top ....

V. Screenshots: Adding VBA Codes in Excel

Excel 2002-2003 (or Earlier)


Screenshot No. 1: Microsoft Excel 2002-2003

Screenshot No. 2: Visual Basic Editor



VBA
Code

Excel 2007
Screenshot No. 3: 2007 Tools Developer Tab

Screenshot No. 4: Developer Tab excel option



( Help

)

Screenshot No. 5:

VBA Macro Security Level Powerful


Operation Macro Security
Screenshot No.
6:

Screenshot No. 7:Developer Tab Code


Macro Security

Screen

...Back to Top ....

VI. Screenshots: Use of VBA Functions in Excel Worksheet


Function Excel Spreadsheet

Insert function select a category
User Defined Function

Excel Formula


Air_cmh Function

Optional Assign Assigned value

dP_Pa = 1
V_mps = 8
E_mm = 0.09
Excel Style: Drag-Coppy

Chart
1%

safety factor

Excel Calculation Sheet File


Function VBA Codes
file


Function VBA Codes
Function
Cell Copy Paste Special

values Chart Manually


...Back to Top ....

VII. Html Color Coding by VBA


VBA code
VBA html format
MS Word

format html


VBA Code
...Back to Top ....

VIII. References
1. "Duct Design", Chapter 21, ASHRAE Handbook: Fundamentals, 2009.
2. Visual Basic for Applications
3. Using Flow Chart - Flowcharting[ http://www.nos.org/htm/basic2.htm ]
4. HVAC Duct Sizing[ http://chawlwin.blogspot.com/2009/07/hvac-duct-sizing.html ]

Disclaimer
Programming



...Back to Top ....


Posted by Ko Chaw - at 9:53 PM
Labels: HVAC, MEP Design, VBA

NO COMMENTS:
Post a Comment
Newer Post

Home

Subscribe to: Post Comments (Atom)

Construction Industry





Blog



[email protected]

Older Post

You might also like