Invalid qualifier excel macro

martinsk

New Member
Joined
Feb 12, 2014
Messages
2
Hi everyone, Am having a litter trouble with Macro in excel. here is my code.

Sub sampleworksheet()</SPAN>
Dim cursheet As Worksheet</SPAN>
Dim j As Integer</SPAN>
Dim curname As String</SPAN>
Dim channame As String</SPAN>
Dim modifiedchanname As String</SPAN>

'itterate all worksheets in workbook</SPAN>
For j = 1 To ActiveWorkbook.Worksheets.Count</SPAN>
cursheet = ActiveWorkbook.Worksheets(j)</SPAN>
If Not IsEmpty(curname.Cells(1, 1)) Then</SPAN>
channame = cursheet.Cells(4, 2)</SPAN>
curname = cursheet.Name</SPAN>


modifiedchanname = channame</SPAN>

'channame must be valid excel worksheet name!!!!!!!!!!!!</SPAN>
cursheet.Name = modifiedchanname</SPAN>
End If</SPAN>
Next j</SPAN>
End Sub</SPAN>

I am getting "invalid qualifer" at curname (i have highlighted it in the code). I cant seem to get my head around.

Can anyone help please, i will be soo happy :)
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Welcome to the board.

It's hard to read your code like that, not sure how it ended up just written like a paragraph of text...

But I think the problem is This
cursheet = ActiveWorkbook.Worksheets(j)
should be
Set cursheet = ActiveWorkbook.Worksheets(j)
 
Upvote 0
Please use code tags when posting code.

curname should read cursheet.

Code:
Sub sampleworksheet()
Dim cursheet As Worksheet
Dim j As Integer
Dim curname As String
Dim channame As String
Dim modifiedchanname As String
'itterate all worksheets in workbook
For j = 1 To ActiveWorkbook.Worksheets.Count
cursheet = ActiveWorkbook.Worksheets(j)
If Not IsEmpty(cursheet.Cells(1, 1)) Then
channame = cursheet.Cells(4, 2)
curname = cursheet.Name
modifiedchanname = channame
'channame must be valid excel worksheet name!!!!!!!!!!!!
cursheet.Name = modifiedchanname
End If
Next j
End Sub
 
Upvote 0
Try declaring curname as a Worksheet and add this as the first line in the loop.
Code:
Set curname = ActiveWorkbook.Worksheets(j)
 
Upvote 0
Oops, misread code.

Try this.
Code:
Sub sampleworksheet()
Dim cursheet As Worksheet
Dim j As Integer
Dim channame As String
Dim curname As String
Dim modifiedchanname As String

    'itterate all worksheets in workbook
    For j = 1 To ActiveWorkbook.Worksheets.Count
    
        Set cursheet = ActiveWorkbook.Worksheets(j)
        
        If Not IsEmpty(cursheet.Cells(1, 1)) Then
            channame = cursheet.Cells(4, 2)
            curname = cursheet.Name
            modifiedchanname = channame
            'channame must be valid excel worksheet name!!!!!!!!!!!!
            cursheet.Name = modifiedchanname
        End If
        
    Next j
    
End Sub
 
Upvote 0
Thank you soo much guys, it worked :).

Next time I will use code tags when posting a code. Again thank you guys
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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