Run-time error: '1004': Method 'Range' of object '_Global' failed

LearningExcel2024

New Member
Joined
Jan 15, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi,

As the title says, I am very new to Excel, more specifically VBA, and I'm working on a test project to help familiarise myself with the various concepts involved. The test project is namely a UserForm that enables the user to select a cell, or range of cells, to input a desired term or text in their selection. I am pulling the ranges using the Refedit control, as it is dynamic and seems, to me anyway, to be user-friendly.

The positive is that I have got it to work i.e. if the user has selected a range and included a term in the provided text box, it will populate the Worksheet as designed. However, there is a behaviour that is prompting the aforementioned error: the user doesn't select a range and clicks 'Input.'

I am obviously looking for a solution - and I have spent the past two days reading various resources in an attempt to resolve it myself - but more so to understand the reason(s) for the error.

I have attached related screenshots of the UserForm, Worksheet, Error dialog and of course the code.

Any guidance would be greatly appreciated.

Thank you.

Screenshot 2024-01-15 195401.pngScreenshot 2024-01-15 195559.pngScreenshot 2024-01-15 195630.pngScreenshot 2024-01-15 195744.png
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I'd say your problem is that you can't use a string variable value as a range reference without concatenating quotation marks and that can be tricky (and probably isn't necessary in this case). You might try changing the variable to a range object instead. Can't say for sure because you didn't reveal the value of the variable. Perhaps you don't know that you should troubleshoot code by stepping through it (F8) and check your values and references as you go. Note that you usually have to execute a line (move off of it onto the next line) otherwise a variable won't get a value from a line that has not "run".
 
Upvote 1
I'd say your problem is that you can't use a string variable value as a range reference without concatenating quotation marks and that can be tricky (and probably isn't necessary in this case). You might try changing the variable to a range object instead. Can't say for sure because you didn't reveal the value of the variable. Perhaps you don't know that you should troubleshoot code by stepping through it (F8) and check your values and references as you go. Note that you usually have to execute a line (move off of it onto the next line) otherwise a variable won't get a value from a line that has not "run".
Hi, Micron.

Thank you for taking the time to review my post and offer your thoughts.

I studied your post for a few good hours last night, prompting further research, which ultimately lead me to starting from scratch, the result of which being a much simpler, actually functioning, set of code, as shown below:

So thank you again for helping me to better understand some of the principles involved.

Screenshot 2024-01-16 131055.png
 
Upvote 0
Just FYI, str is actually a built-in VBA function, so not a great name for a variable.
 
Upvote 1
And for the counterpoint to the common (in VBA anyway) conventions, go here: Making Wrong Code Look Wrong

You can skip to the section about 2/3 of the way down titled I'm Hungary if you just want the salient bit (as far as this thread is concerned) in a hurry. ;)
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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