Syntax must be incorrect for range reference

rmunn

New Member
Joined
Jan 28, 2010
Messages
10
The following sub to create and name wsheets results naming the new sheet with the value of "A9" only, but what I want to name the new sheet is "A9" + "B9". Where have I gone wrong?
Thanks.

Sub CreateWorksheets()
Dim newSheet As Worksheet, itemSheet As Worksheet
Dim cell As Object
Dim itemrange As String

Set itemSheet = Sheets("BIDFORM")

Application.ScreenUpdating = False
itemrange = "A9:B9:" & itemSheet.Range("A9").End(xlDown).Address
For Each cell In itemSheet.Range(itemrange)
If SheetExists(cell.Value) = False Then
Sheets.Add Before:=Sheets("BACK SHEET"), _
Type:="C:\Path\File"
Set newSheet = ActiveShee
newSheet.Name = cell.Value

End If
Next cell
Application.ScreenUpdating = True

End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Change this

itemrange = "A9:B9:" & itemSheet.Range("A9").End(xlDown).Address

to this

itemrange = "A9:" & itemSheet.Range("A9").End(xlDown).Address
 
Upvote 0
Thanks for your quick response. I have already tried your suggestion, but the results are the same.
 
Upvote 0
I didn't think you could name a sheet A9 + B9, but you can. I think you want to say
Code:
newSheet.Name = cell.Value & " + " & cell.offset(0,1).Value
 
Upvote 0
I tried GeofW's suggestion, and strangely the result was literally B9 + A9, meaning that the position of A9 and B9 were reversed, and the + also appeared in the result.
 
Upvote 0
You should post your worksheet contents. Hard to tell what you really want (as you can see from GeofW's answer, which was logical but maybe not what you want).
 
Upvote 0
Perhaps I should have been more clear. What I am trying to do is to loop through cols A & B and combine those values at each row, with the resulting string being inserted as the name of the newly inserted sheet.
I have no problem with the inserting of the sheets, but can't get the name to include the combined value. When I run what I posted, the first sheet inserted was named A9, and the second sheet inserted was named B9, and so on down the columns.
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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