AWG Wire Gauge lookup table

bassplr19

New Member
Joined
Sep 11, 2023
Messages
35
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I'm trying to convert AWG wire gauges to mm2 to check if a wire fits in a wire range. I'm using a lookup table where I've manually populated 14-1000 MCM wires to mm2.

My VBA is working on everything except "1/0" - it's working fine on 2/0, 3/0, and 4/0

Here's where it breaks:
conv_AWG = WorksheetFunction.Lookup(wire, wireTableAWG, wireTablemm)

While checking 4/0, I hover over wire and see that wire="4/0" and then while checking 1/0 right before it breaks I see that wire = "1/0"
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I'm trying to convert AWG wire gauges to mm2 to check if a wire fits in a wire range. I'm using a lookup table where I've manually populated 14-1000 MCM wires to mm2.

My VBA is working on everything except "1/0" - it's working fine on 2/0, 3/0, and 4/0

Here's where it breaks:
conv_AWG = WorksheetFunction.Lookup(wire, wireTableAWG, wireTablemm)

While checking 4/0, I hover over wire and see that wire="4/0" and then while checking 1/0 right before it breaks I see that wire = "1/0"
Are you able to use XL2BB to post sample data and appropriate code?
 
Upvote 0
AWGmm2
1000500
750400
600300
500240
300185
250150
4/0107.2193
3/085.0288
2/067.4309
1/053.4751
142.4077
233.6308
326.6705
421.1506
516.7732
613.3018
710.5488
88.3656
96.6342
105.2612
114.1723
123.3088
132.624
142.0809


Input Power WireDrive RangeColumn1
1414 - 6],Table2[@[Drive Range]])]TRUE
1414 - 6],Table2[@[Drive Range]])]TRUE
1414 - 6],Table2[@[Drive Range]])]TRUE
1414 - 6],Table2[@[Drive Range]])]TRUE
1414 - 6],Table2[@[Drive Range]])]TRUE
1414 - 6],Table2[@[Drive Range]])]TRUE
1014 - 6],Table2[@[Drive Range]])]TRUE
814 - 6],Table2[@[Drive Range]])]TRUE
814 - 6],Table2[@[Drive Range]])]TRUE
48 - 2],Table2[@[Drive Range]])]TRUE
414 - 2/0#VALUE!
214 - 2/0#VALUE!
36 - 2/0#VALUE!
26 - 2/0#VALUE!
1/02 - 300#VALUE!
2/02 - 300#VALUE!
4/02 - 300],Table2[@[Drive Range]])]FALSE
(2) 1/0(2) 3 - 4/0#VALUE!
(2) 3/0(2) 2/0 - 300#VALUE!
(2) 3/0(2) 2/0 - 300#VALUE!
1414 - 6],Table2[@[Drive Range]])]TRUE
1414 - 6],Table2[@[Drive Range]])]TRUE
1414 - 6],Table2[@[Drive Range]])]TRUE
1414 - 6],Table2[@[Drive Range]])]TRUE
1414 - 6],Table2[@[Drive Range]])]TRUE
1414 - 6],Table2[@[Drive Range]])]TRUE
1214 - 6],Table2[@[Drive Range]])]TRUE
814 - 6],Table2[@[Drive Range]])]TRUE
814 - 6],Table2[@[Drive Range]])]TRUE
614 - 6],Table2[@[Drive Range]])]TRUE
445140],Table2[@[Drive Range]])]TRUE
314 - 2/0#VALUE!
214 - 2/0#VALUE!
236679#VALUE!
3652636679#VALUE!
365572 - 300#VALUE!
365862 - 300#VALUE!
(2) 1/0(2) 3 - 4/0#VALUE!
(2) 2/0(2) 3 - 4/0#VALUE!
(2) 3/0(2) 2/0 - 300#VALUE!
1414 - 6],Table2[@[Drive Range]])]TRUE
1414 - 6],Table2[@[Drive Range]])]TRUE
1414 - 6],Table2[@[Drive Range]])]TRUE
1414 - 6],Table2[@[Drive Range]])]TRUE
1414 - 6],Table2[@[Drive Range]])]TRUE
1414 - 6],Table2[@[Drive Range]])]TRUE
1414 - 6],Table2[@[Drive Range]])]TRUE
1414 - 6],Table2[@[Drive Range]])]TRUE
1214 - 6],Table2[@[Drive Range]])]TRUE
1014 - 6],Table2[@[Drive Range]])]TRUE
845140],Table2[@[Drive Range]])]TRUE
845140],Table2[@[Drive Range]])]TRUE
645140],Table2[@[Drive Range]])]TRUE
845140],Table2[@[Drive Range]])]TRUE
645140],Table2[@[Drive Range]])]TRUE
445140],Table2[@[Drive Range]])]TRUE
336679#VALUE!
12 - 300#VALUE!
365262 - 300#VALUE!
36557(2) 3 - 4/0#VALUE!
(2) 1/0(2) 3 - 4/0#VALUE!
(2) 1/0(2) 3 - 4/0#VALUE!
(2) 2/0(2) 2/0 - 300#VALUE!
(2) 4/0(2) 2/0 - 300#VALUE!
(3) 2/0(4) 2/0 - 300#VALUE!
(3) 2/0(4) 2/0 - 300#VALUE!
(3) 3/0(4) 2/0 - 300#VALUE!
(3) 4/0(4) 2/0 - 300#VALUE!
(3) 4/0(4) 2/0 - 300#VALUE!
(4) 4/0(4) 3/0 - 300#VALUE!
(4) 4/0(4) 4/0 - 300],Table2[@[Drive Range]])]TRUE
(4) 350(4) 4/0 - 300],Table2[@[Drive Range]])]TRUE
(4) 350(4) 4/0 - 300],Table2[@[Drive Range]])]TRUE


VBA Code:
Function inWireRange(wire As Variant, wireRange As Variant)
    Dim minWire As Variant
    Dim maxWire As Variant
    Dim multWires As Collection
    Dim multRange As Collection
    Dim noWires As Integer
    Dim noRange As Integer
    
    ' Clean wire range
    wireRange = Replace(wireRange, " ", "")
    wire = Trim(wire)
    wireRange = Trim(wireRange)
    
    Set multWires = noCond(wire)
    Set multRange = noCond(wireRange)
    
    ' Find no. conductors and wire size of wire to check
    noWires = multWires(1)
    wire = multWires(2)
    
    ' Find no. conductors and wire range to check against
    noWireRange = multRange(1)
    wireRange = multRange(2)
          
    ' Check no of conductors
    If noWires > noWireRange Then
            inWireRange = False
            Exit Function
    End If
    
    ' Separate out if multiple torque ranges "OR"
    If InStr(wireRange, "OR") > 0 Then
        
        minWire = Left(wireRange, InStr(wireRange, "-") - 1)
        maxWire = Right(wireRange, Len(wireRange) - InStrRev(wireRange, "-"))
    ElseIf InStr(wireRange, "-") > 0 Then 'Split the range into separate variables

        minWire = Left(wireRange, InStr(wireRange, "-") - 1)
        maxWire = Right(wireRange, Len(wireRange) - InStr(wireRange, "-"))
    Else ' If range is only one wire, turn into "Range"
        minWire = wireRange
        maxWire = wireRange
    End If
    
    ' Convert AWG to mm2 for comparison
    minWire = conv_AWG(minWire)
    maxWire = conv_AWG(maxWire)
    wire = conv_AWG(wire)
    

    ' Check order of wire range
    If minWire > maxWire Then
        minWireTemp = maxWire
        maxWire = minWire
        minWire = minWireTemp
    End If
    
    If (wire >= minWire) And (wire <= maxWire) Then
        inWireRange = True
    Else
        inWireRange = False
    End If
        
End Function
' Convert AWG to mm2 for comparison
Function conv_AWG(wire)
    Dim wireTableAWG As Range
    Dim wireTablemm As Range
    
    Set wireTableAWG = Range("AWG_Conv[AWG]")
    Set wireTablemm = Range("AWG_Conv[mm2]")
 
    If IsNumeric(wire) Then
        wire = Int(wire)
    Else
        wire = Trim(wire) ' Make sure there are no spaces
    End If
    
    If InStr(wire, "/") > 0 Then
        wire = Left(wire, 1) + "O"
    End If
 
    conv_AWG = WorksheetFunction.Lookup(wire, wireTableAWG, wireTablemm)
End Function
' Separate no of conductors from wire range
Function noCond(wire)
    Dim outputW As Collection
    Set outputW = New Collection
    
    wire = Replace(wire, " ", "")
    
    If InStr(wire, "(") > 0 Then
        noWires = Mid(wire, InStr(wire, ")") - 1, 1)
        wireRange = Right(wire, Len(wire) - InStr(wire, ")"))
    Else
        noWires = 1
        wireRange = wire
    End If
    
    outputW.Add noWires
    outputW.Add wireRange
    
    Set noCond = outputW
End Function
 
Upvote 0
Strike out
VBA Code:
If InStr(wire, "/") > 0 Then
        wire = Left(wire, 1) + "O"
    End If
I was experimenting
 
Upvote 0
I cheated:
VBA Code:
    If wire = "1/0" Then
        conv_AWG = 53.471
    ElseIf wire = "2/0" Then
        conv_AWG = 67.4309
    ElseIf wire = "3/0" Then
        conv_AWG = 85.0288
    ElseIf wire = "4/0" Then
        conv_AWG = 107.2193
    Else
        conv_AWG = WorksheetFunction.Lookup(wire, wireTableAWG, wireTablemm)
    End If
 
Upvote 0
Solution

Forum statistics

Threads
1,223,313
Messages
6,171,369
Members
452,397
Latest member
ddneptune

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