Variable has no value

KhallP

Board Regular
Joined
Mar 30, 2021
Messages
157
Office Version
  1. 2016
Platform
  1. Windows
I'm having a problem with the code, my program always works, but sometimes (I don't know why) the variable A2 (only happens with this one) is not passed and takes value 0, because this could be happening?

VBA Code:
Private Sub cb_Agrid_Click()

If Not IsNumeric(in_A2.Value) Or Trim(in_A2.Text) = "" Then
    MsgBox "'Table Side (Primeiro Campo) ' está vazio ou contém letras", vbExclamation
    
ElseIf Not IsNumeric(in_A4.Value) Or Trim(in_A4.Text) = "" Then
    MsgBox "'Table Side (Segundo Campo) ' está vazio ou contém letras", vbExclamation
    
ElseIf Not IsNumeric(in_A1.Value) Or Trim(in_A1.Text) = "" Then
    MsgBox "'Spindle Side (Primeiro Campo) ' está vazio ou contém letras", vbExclamation
    
ElseIf Not IsNumeric(in_A3.Value) Or Trim(in_A3.Text) = "" Then
    MsgBox "'Spindle Side (Segundo Campo) ' está vazio ou contém letras", vbExclamation
    
ElseIf Not IsNumeric(in_A_orig.Value) Or Trim(in_A_orig.Text) = "" Then
    MsgBox "'1850 A Parameter' está vazio ou contém letras", vbExclamation
    
'Caso contrário os valores inseridos são atribuídos ás variáveis correspondentes
Else

    Dim TestBar, Indicator1, Indicator2, Indicator3, Indicator4, GridDif180, GridDif, GridDif0, A_Grid As Double
    
    A2 = in_A2.Value
    A4 = in_A4.Value

    TestBar = in_TestBarLength.Value
    Indicator1 = in_A1.Value / 1000
    Indicator2 = in_A2.Value / 1000
    Indicator3 = in_A3.Value / 1000
    Indicator4 = in_A4.Value / 1000
    
  
    GridDif0 = (Indicator2 - Indicator1)
    GridDif180 = (Indicator4 - Indicator3)
    
    A_Grid_Orig = in_A_orig.Value
    
    GridDif = ((GridDif0 - GridDif180) / 2) * -1
    
    A_Grid = Atn(GridDif / TestBar) * 57.2957795130823
    A_Grid = Format(A_Grid, "0.####") * 10000
    
    out_Agrid.Value = A_Grid
    A_Grid_Final = A_Grid_Orig + A_Grid
    out_Agrid_Final.Value = A_Grid_Final
    
End If
End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I'm having a problem with the code, my program always works, but sometimes (I don't know why) the variable A2 (only happens with this one) is not passed and takes value 0, because this could be happening?

VBA Code:
Private Sub cb_Agrid_Click()

If Not IsNumeric(in_A2.Value) Or Trim(in_A2.Text) = "" Then
    MsgBox "'Table Side (Primeiro Campo) ' está vazio ou contém letras", vbExclamation
   
ElseIf Not IsNumeric(in_A4.Value) Or Trim(in_A4.Text) = "" Then
    MsgBox "'Table Side (Segundo Campo) ' está vazio ou contém letras", vbExclamation
   
ElseIf Not IsNumeric(in_A1.Value) Or Trim(in_A1.Text) = "" Then
    MsgBox "'Spindle Side (Primeiro Campo) ' está vazio ou contém letras", vbExclamation
   
ElseIf Not IsNumeric(in_A3.Value) Or Trim(in_A3.Text) = "" Then
    MsgBox "'Spindle Side (Segundo Campo) ' está vazio ou contém letras", vbExclamation
   
ElseIf Not IsNumeric(in_A_orig.Value) Or Trim(in_A_orig.Text) = "" Then
    MsgBox "'1850 A Parameter' está vazio ou contém letras", vbExclamation
   
'Caso contrário os valores inseridos são atribuídos ás variáveis correspondentes
Else

    Dim TestBar, Indicator1, Indicator2, Indicator3, Indicator4, GridDif180, GridDif, GridDif0, A_Grid As Double
   
    A2 = in_A2.Value
    A4 = in_A4.Value

    TestBar = in_TestBarLength.Value
    Indicator1 = in_A1.Value / 1000
    Indicator2 = in_A2.Value / 1000
    Indicator3 = in_A3.Value / 1000
    Indicator4 = in_A4.Value / 1000
   
 
    GridDif0 = (Indicator2 - Indicator1)
    GridDif180 = (Indicator4 - Indicator3)
   
    A_Grid_Orig = in_A_orig.Value
   
    GridDif = ((GridDif0 - GridDif180) / 2) * -1
   
    A_Grid = Atn(GridDif / TestBar) * 57.2957795130823
    A_Grid = Format(A_Grid, "0.####") * 10000
   
    out_Agrid.Value = A_Grid
    A_Grid_Final = A_Grid_Orig + A_Grid
    out_Agrid_Final.Value = A_Grid_Final
   
End If
End Sub
in the end my code creates a PDF file with the values of the corresponding variables and in the PDF daughter the value appears right, can someone help me?

capturar.JPG
 
Upvote 0
Your code has:

A2 = in_A2.Value

but doesn't use A2?

Where are you finding that A2 has the value 0? Are you declaring A2 somewhere else in your code? Can you post the code?
 
Upvote 0

Forum statistics

Threads
1,214,959
Messages
6,122,476
Members
449,087
Latest member
RExcelSearch

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