Run time error 1004: Method 'Range' of object '_global' failed

ebculver

New Member
Joined
Jul 3, 2024
Messages
2
Office Version
  1. 2021
Platform
  1. Windows
Hello,

I am trying to create a VBA userform that calculates a future date based on a given initial date, initial flowrate, final pressure, and average pressure loss per day. Right now, my user form is set up to copy and paste daily pressure data into a textbox, and the VBA code calculates the average pressure loss per day. My issue is that my code doesn't seem to recognize the list of pressures I paste into the textbox. I am pretty new to VBA so I am not savvy enough to diagnose the error through debugging, however I did identify where it is located. I attached my code, user form with dummy values, and pertinent textbox properties box below. Any thoughts would be appreciated!

1720027419441.png
1720027480238.png
1720027644680.png
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Have you tried it without using Range()?

VBA Code:
Set PressureData = txtpressuredata.Text
 
Upvote 0
Your For Each Cell in PressureData loop code expects to be working with data that is in worksheet cells, but you appear to want to feed it the text data contained in TextBox txtpressuredata. However that requires replacing the cell loop code with something more suited to the strings in the text box.

VBA Code:
    Dim SA As Variant
    SA = Split(Me.txtpressuredata.Text, vbLf)
  
    If UBound(SA) > 0 Then
        TotalChange = CDbl(Trim(SA(UBound(SA)))) - CDbl(Trim(SA(0)))
        DataCount = UBound(SA) + 1
    Else
        DataCount = 0
    End If

(note that TotalChange is just my convenient simplification and not a true average. You are the expert on what it should be :) )
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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