Invalid Procedure Error 5 when assigning value to variable

SirProperJob

New Member
Joined
Feb 15, 2013
Messages
5
Hi,

I'm having problems with an error showing when I try to assign a value to a string variable, saying that's an invalid procedure, when I haven't even called one! It works ok if i step through the code, but if i try to run the whole lot, the error keeps coming up. My code is as below:

Code:
Sub DanoneExtract()
Dim wbOpen, wbTemp As Workbook
Dim iRow, iUnits, iSheets, x, c, ws As Integer
Dim strExtension, strCry, strCat, strBO, strBrand, strPL, strPriceSeg, strCal, strCarb, strWS, strFl, strPackMat, strPackType, strPackSize, strGeoScope, strChan As String
Dim dblVolShare, dblTotVol, dblVol, dblVal As Double
Const strPath As String = "G:\EDIT\REPORTS\SINGLE CLIENT REPORTS\Danone\2013\00_Project Management\Value Methodology\Suzanna\Dummy Data_Template Test\"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ChDir strPath
strExtension = Dir(strPath & "*.xls*")
Set wbTemp = Workbooks.Open("G:\EDIT\REPORTS\SINGLE CLIENT REPORTS\Danone\2013\00_Project Management\Value Methodology\Suzanna\DanoneUploadTemplate.xlsx")
Do While strExtension <> ""
        Set wbOpen = Workbooks.Open(strPath & strExtension)
        wbOpen.Worksheets(1).Activate
        strCry = Right(Range("A1").Value, Len(Range("A1").Value) - 28).Value
        iRow = 2
        iSheets = wbOpen.Worksheets.Count

The error occurs when I try to assign the value Right(Range("A1").Value, Len(Range("A1").Value) - 28).Value to strCry.

Any ideas as to why this might be happening? Later on in the code i have assigned similar values to other variables with no problems.
 
Last edited:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
You are not correct on your declarations. this code:

Code:
Dim strExtension, strCry, strCat, strBO, strBrand, strPL, strPriceSeg, strCal, strCarb, strWS, strFl, strPackMat, strPackType, strPackSize, strGeoScope, strChan As String

set strChan as a String. The other variables are Variant's (no type declaration). You need to repeat the "As String" part for each String variable. Likewise for Long, Integer, ...
 
Upvote 0
Thanks for replying and I tried setting all my variables as you suggested, but i still get the same error. It's really frustrating, because it works fine when i step through each line, but when i try to run the whole thing it comes up with this error!
 
Upvote 0
It has the text "PRICE COLLECTION TEMPLATE - ARGENTINA". I can't change this, as much as i'd love to, as my "superiors" have sigend off on this template. Obviously, "ARGENTINA" changes for each file.
 
Upvote 0
Silly me, you have a superfluous .Value on the end - your line should be:

Code:
strCry = Right(Range("A1").Value, Len(Range("A1").Value) - 28)
 
Upvote 0
What is it you are trying to extract from A1?

If it's what's after PRICE COLLECTION TEMPLATE - .
Code:
strCry = Trim(Mid(Range("A1").Value, 28))
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

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