Application.Worksheetfunction.Mid - Run-time error '438: Object doesn't support this property or method

TheWildAfrican

Board Regular
Joined
Apr 23, 2013
Messages
70
Hello,

I was wondering if the Application.Worksheetfunction.Mid works within VBA in Excel 2010 . Everytime I execute the macro, it runs a "run-time error 438: Object doesn't support this property or method".

I'm trying to use the "Mid" Excel function to out a piece of text from the middle of a text entry. Please find my code below and advise. Thanks for your help!!

Dim mid_start, mid_end, cnt_columns, i As Integer
Dim pay_status As String

Range("R205").Activate
i = 0

While (ActiveCell.Offset(i, 0).Value = pay_status)
pay_status = ActiveCell.Offset(i, 0).Value


ActiveCell.Offset(i, 21).Value = Application.WorksheetFunction.Mid((ActiveCell.Offset(i, 0).Value), _ ActiveCell.Offset(i - 3, 21).Value, 1)
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi
Welcome to the board

vba has its own string functions that you can use. They are very similar to the worksheet functions.

Check the vba help for the function Mid().
 
Upvote 0
I'm not sure that function exists, but you can use the VBA Mid(string, start, how many):
Code:
Dim mid_start As Integer
Dim mid_end As Integer
Dim cnt_columns As Integer
Dim i As Integer
Dim pay_status As String

Range("R205").Activate
i = 0

While (ActiveCell.Offset(i, 0).Value = pay_status)
    pay_status = ActiveCell.Offset(i, 0).Value

    ActiveCell.Offset(i, 21).Value = Mid(ActiveCell.Offset(i, 0).Value, _
        ActiveCell.Offset(i - 3, 21).Value, 1) 
Loop While

Here is the actual syntax:
MID(text, start_position, number_of_characters)
 
Upvote 0
Hi again,

Thanks for your help, it was quite helpful. However, my code keep freezing on me as I have 80 columns of this line:

ActiveCell.Offset(i, 21).Value = Application.WorksheetFunction.Mid((ActiveCell.Offset(i, 0).Value), ActiveCell.Offset(i - 3, 21).Value, 1)

and ~600,000 rows to loop through. I'd like to know how to reference an absolute cell for the start position (i.e ActiveCell.Offset(i - 3, 21).Value) in VBA.

Thanks for your help.
 
Upvote 0
Absolute references start with a dollar sign, like $A$33. In VBA, since you are putting a reference in the code, anything that has A1 addressing or Cells(1,1) referencing is as good as absolute. I hope that helps!
 
Upvote 0
Thanks, man!! Unfortunately, I'm still having issues. I've tried using the absolute reference (hard coded) withiut any luck. If it's okay with you, I'd like to send you a direct message of the codes...Thanks, again.
 
Upvote 0
Post them here. A private message doesn't contain the history and context of the problem, so I have to jump back and forth. I did notice that you define and set mid_* variables, but never use them. Use "
Code:
" tags to post your code. Also, where exactly are you having the problem? Compiling or run-time? Either way, what is being highlighted as the problem?
 
Upvote 0
Thanks for your response. Excel crashes everytime I run the macro. The first row of the codes works; but excel stop responding afetr the first loop...I don't know if it's because of the enomorous volume of the data....Yes, I initially thought I might need the mid_* variable, I'm not sure there is a need for the variable.... Please find the code below
Sub Doc_()
'RU 2934 uses this code to simplify loan level data
'Columns from "R". Rows from "205" = "R205"
Dim mid_start, mid_end, cnt_columns, i As Integer
Dim pay_status As String
'initialize variables
mid_start = 0
mid_end = 0
cnt_columns = 0 'Cells(202, 39)
Range("R205").Activate
i = 0
'While Not (IsEmpty(ActiveCell.Offset(i, 0).Value))
' pay_status = ActiveCell.Offset(i, 0).Value
' mid_start = i
While (ActiveCell.Offset(i, 0).Value <> "") 'pay_status) '<>""
pay_status = ActiveCell.Offset(i, 0).Value

'getting the loan status

ActiveCell.Offset(i, 21).Value = Mid((ActiveCell.Offset(i, 0).Value), ActiveCell.Offset(i - 3, 21).Value, 1)
ActiveCell.Offset(i, 22).Value = Mid((ActiveCell.Offset(i, 0).Value), ActiveCell.Offset(i - 3, 22).Value, 1)
ActiveCell.Offset(i, 23).Value = Mid((ActiveCell.Offset(i, 0).Value), ActiveCell.Offset(i - 3, 23).Value, 1)

i = 1 + 1
Wend

'i = i + 1
'Wend
End Sub
 
Upvote 0
You might also be in an endless loop. If "Mid((ActiveCell.Offset(i, 0).Value), ActiveCell.Offset(i - 3, 21).Value, 1)" doesn't evaluate to a start position for the Mid statement, the "While (ActiveCell.Offset(i, 0).Value <> "")" may never happen. Try this line of code and check the immediate window for results:
Code:
Debug.Print ActiveCell.Offset(i - 3, 21).Value
Step through the code and see what is being tested. With an enormous amount of data, you won't be able to check much, but it might help pin this down.
 
Upvote 0

Forum statistics

Threads
1,215,472
Messages
6,125,007
Members
449,203
Latest member
Daymo66

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