Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Can't concatenate

What's wrong with this:

Dim SrcWksht As Worksheet
Dim WkshtMon As Worksheet

Set SrcWksht = ThisWorkbook("Sheet1")

wkshtmon.Name=srcwksht.name&" - Monthly"<---Compile error - expected
end of statement

Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Can't concatenate

You need code like

Set SrcWksht = ThisWorkbook.Worksheets("Sheet1")
wkshtmon.Name=srcwksht.name & " - Monthly"

Note the space before the & character. Without the space, VBA
treats the & character as a data type conversion operator.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"davegb" wrote in message
oups.com...
What's wrong with this:

Dim SrcWksht As Worksheet
Dim WkshtMon As Worksheet

Set SrcWksht = ThisWorkbook("Sheet1")

wkshtmon.Name=srcwksht.name&" - Monthly"<---Compile error -
expected
end of statement

Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Can't concatenate

Thanks, Chip!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Can't concatenate

I fixed it, but when I run it, I get an "Object variable or with block
variable not set" error.

Sub CountMonth()
Dim CountArray(1 To 12, 1 To 7)
Dim SrcWksht As Worksheet
'Dim SrcWkshtName As String
Dim MonWksht As Worksheet
Dim strCntctDate As String
Dim strCntctMo As String


Set SrcWksht = ThisWorkbook.Sheets("Sheet1")

MonWksht.Name = SrcWksht.Name & " - Monthly"<---error

Any suggestions?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Can't concatenate

Sure,
you haven't set MonWksht to anything.

So you have an object variable undefined/Not Set.

--
Regards,
Tom Ogilvy
"davegb" wrote in message
oups.com...
I fixed it, but when I run it, I get an "Object variable or with block
variable not set" error.

Sub CountMonth()
Dim CountArray(1 To 12, 1 To 7)
Dim SrcWksht As Worksheet
'Dim SrcWkshtName As String
Dim MonWksht As Worksheet
Dim strCntctDate As String
Dim strCntctMo As String


Set SrcWksht = ThisWorkbook.Sheets("Sheet1")

MonWksht.Name = SrcWksht.Name & " - Monthly"<---error

Any suggestions?





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Can't concatenate


Tom Ogilvy wrote:
Sure,
you haven't set MonWksht to anything.

So you have an object variable undefined/Not Set.

--
Regards,
Tom Ogilvy


Thanks, Tom. So I can't determine a worksheet by setting it's name
based on another worksheet? Would it work if I set Monwksht to some
other sheet, like Sheet1, then changed it to SrcWksht.Name + "Monthly"?
I don't want to have to input the second sheet name directly. I want it
to be the source sheet name + "monthly". Is there a way to do this?


"davegb" wrote in message
oups.com...
I fixed it, but when I run it, I get an "Object variable or with block
variable not set" error.

Sub CountMonth()
Dim CountArray(1 To 12, 1 To 7)
Dim SrcWksht As Worksheet
'Dim SrcWkshtName As String
Dim MonWksht As Worksheet
Dim strCntctDate As String
Dim strCntctMo As String


Set SrcWksht = ThisWorkbook.Sheets("Sheet1")

MonWksht.Name = SrcWksht.Name & " - Monthly"<---error

Any suggestions?


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Can't concatenate

Your code says

set the name of some unknown worksheet to have the name of "Sheet1" & " -
Monthly"

Some way you have to establish which worksheet you want to rename.

--
Regards,
Tom Ogilvy

"davegb" wrote in message
ups.com...

Tom Ogilvy wrote:
Sure,
you haven't set MonWksht to anything.

So you have an object variable undefined/Not Set.

--
Regards,
Tom Ogilvy


Thanks, Tom. So I can't determine a worksheet by setting it's name
based on another worksheet? Would it work if I set Monwksht to some
other sheet, like Sheet1, then changed it to SrcWksht.Name + "Monthly"?
I don't want to have to input the second sheet name directly. I want it
to be the source sheet name + "monthly". Is there a way to do this?


"davegb" wrote in message
oups.com...
I fixed it, but when I run it, I get an "Object variable or with block
variable not set" error.

Sub CountMonth()
Dim CountArray(1 To 12, 1 To 7)
Dim SrcWksht As Worksheet
'Dim SrcWkshtName As String
Dim MonWksht As Worksheet
Dim strCntctDate As String
Dim strCntctMo As String


Set SrcWksht = ThisWorkbook.Sheets("Sheet1")

MonWksht.Name = SrcWksht.Name & " - Monthly"<---error

Any suggestions?




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Can't concatenate

something like this won't work for you

Option Explicit
Sub test()
Dim SrcWksht As Worksheet
Dim WkshtMon As String

Set SrcWksht = ThisWorkbook.Worksheets("Sheet1")

WkshtMon = SrcWksht.Name & " - Monthly "
Debug.Print WkshtMon
End Sub


--


Gary


"davegb" wrote in message
oups.com...
What's wrong with this:

Dim SrcWksht As Worksheet
Dim WkshtMon As Worksheet

Set SrcWksht = ThisWorkbook("Sheet1")

wkshtmon.Name=srcwksht.name&" - Monthly"<---Compile error - expected
end of statement

Thanks.



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Can't concatenate


Tom Ogilvy wrote:
Your code says

set the name of some unknown worksheet to have the name of "Sheet1" & " -
Monthly"

Some way you have to establish which worksheet you want to rename.

--
Regards,
Tom Ogilvy

"davegb" wrote in message
ups.com...

Tom Ogilvy wrote:
Sure,
you haven't set MonWksht to anything.

So you have an object variable undefined/Not Set.

--
Regards,
Tom Ogilvy


Thanks, Tom. So I can't determine a worksheet by setting it's name
based on another worksheet? Would it work if I set Monwksht to some
other sheet, like Sheet1, then changed it to SrcWksht.Name + "Monthly"?
I don't want to have to input the second sheet name directly. I want it
to be the source sheet name + "monthly". Is there a way to do this?


"davegb" wrote in message
oups.com...
I fixed it, but when I run it, I get an "Object variable or with block
variable not set" error.

Sub CountMonth()
Dim CountArray(1 To 12, 1 To 7)
Dim SrcWksht As Worksheet
'Dim SrcWkshtName As String
Dim MonWksht As Worksheet
Dim strCntctDate As String
Dim strCntctMo As String


Set SrcWksht = ThisWorkbook.Sheets("Sheet1")

MonWksht.Name = SrcWksht.Name & " - Monthly"<---error

Any suggestions?



Maybe I didn't explain this clearly. I'm not trying to rename a sheet.
I'm trying to set the variable MonWksht = to an existing worksheet,
which uses the current worksheet's name plus "monthly". For example,
the workbook has a series of sheets named for people on staff. Barry,
Sam, Sue, etc. It also has a series of sheets named "Barry - Monthly",
Sam - Monthly", etc. The source sheet where the macro will get it's
data is in the "Barry" sheet. Then it will count certain codes by month
and put the totals in "Barry - Monthly". I want to set SrcWksht =
"Barry" and MonWksht = "Barry" plus "Monthly" so it knows which sheet
to put the data in. All the sheets already exist. Does that help?

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Can't concatenate

this will do that

ThisWorkbook.Worksheets("Sheet1").Name = "Sheet1 " & "- Monthly "

--


Gary


"davegb" wrote in message
oups.com...

Tom Ogilvy wrote:
Your code says

set the name of some unknown worksheet to have the name of "Sheet1" &
" -
Monthly"

Some way you have to establish which worksheet you want to rename.

--
Regards,
Tom Ogilvy

"davegb" wrote in message
ups.com...

Tom Ogilvy wrote:
Sure,
you haven't set MonWksht to anything.

So you have an object variable undefined/Not Set.

--
Regards,
Tom Ogilvy

Thanks, Tom. So I can't determine a worksheet by setting it's name
based on another worksheet? Would it work if I set Monwksht to some
other sheet, like Sheet1, then changed it to SrcWksht.Name + "Monthly"?
I don't want to have to input the second sheet name directly. I want it
to be the source sheet name + "monthly". Is there a way to do this?


"davegb" wrote in message
oups.com...
I fixed it, but when I run it, I get an "Object variable or with
block
variable not set" error.

Sub CountMonth()
Dim CountArray(1 To 12, 1 To 7)
Dim SrcWksht As Worksheet
'Dim SrcWkshtName As String
Dim MonWksht As Worksheet
Dim strCntctDate As String
Dim strCntctMo As String


Set SrcWksht = ThisWorkbook.Sheets("Sheet1")

MonWksht.Name = SrcWksht.Name & " - Monthly"<---error

Any suggestions?



Maybe I didn't explain this clearly. I'm not trying to rename a sheet.
I'm trying to set the variable MonWksht = to an existing worksheet,
which uses the current worksheet's name plus "monthly". For example,
the workbook has a series of sheets named for people on staff. Barry,
Sam, Sue, etc. It also has a series of sheets named "Barry - Monthly",
Sam - Monthly", etc. The source sheet where the macro will get it's
data is in the "Barry" sheet. Then it will count certain codes by month
and put the totals in "Barry - Monthly". I want to set SrcWksht =
"Barry" and MonWksht = "Barry" plus "Monthly" so it knows which sheet
to put the data in. All the sheets already exist. Does that help?





  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Can't concatenate

How about:
dim monWksht as worksheet
....
set monwksht = nothing
on error resume next
set monwksht = worksheets(SrcWksht.Name & " - Monthly")
on error goto 0
if monwksht is nothing then
'nope--no sheet named that
else
'it worked!
end if





davegb wrote:
<<snipped

Maybe I didn't explain this clearly. I'm not trying to rename a sheet.
I'm trying to set the variable MonWksht = to an existing worksheet,
which uses the current worksheet's name plus "monthly". For example,
the workbook has a series of sheets named for people on staff. Barry,
Sam, Sue, etc. It also has a series of sheets named "Barry - Monthly",
Sam - Monthly", etc. The source sheet where the macro will get it's
data is in the "Barry" sheet. Then it will count certain codes by month
and put the totals in "Barry - Monthly". I want to set SrcWksht =
"Barry" and MonWksht = "Barry" plus "Monthly" so it knows which sheet
to put the data in. All the sheets already exist. Does that help?


--

Dave Peterson
  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Can't concatenate

It is nice to know what you are trying to do, because you code is trying to
do what I described.

If you want monWksht to contain a string, then you wouldn't dimension it as
a worksheet and it wouldn't have a name attribute

Sub CountMonth()
Dim CountArray(1 To 12, 1 To 7)
Dim SrcWksht As Worksheet
'Dim SrcWkshtName As String
Dim MonWksht As String
Dim strCntctDate As String
Dim strCntctMo As String


Set SrcWksht = ThisWorkbook.Sheets("Sheet1")

MonWksht= SrcWksht.Name & " - Monthly

' then you could do

Worksheets(MonWksht).Range("A1") = some value

--
Regards,
Tom Ogilvy



"davegb" wrote in message
oups.com...

Tom Ogilvy wrote:
Your code says

set the name of some unknown worksheet to have the name of "Sheet1" &

" -
Monthly"

Some way you have to establish which worksheet you want to rename.

--
Regards,
Tom Ogilvy

"davegb" wrote in message
ups.com...

Tom Ogilvy wrote:
Sure,
you haven't set MonWksht to anything.

So you have an object variable undefined/Not Set.

--
Regards,
Tom Ogilvy

Thanks, Tom. So I can't determine a worksheet by setting it's name
based on another worksheet? Would it work if I set Monwksht to some
other sheet, like Sheet1, then changed it to SrcWksht.Name +

"Monthly"?
I don't want to have to input the second sheet name directly. I want

it
to be the source sheet name + "monthly". Is there a way to do this?


"davegb" wrote in message
oups.com...
I fixed it, but when I run it, I get an "Object variable or with

block
variable not set" error.

Sub CountMonth()
Dim CountArray(1 To 12, 1 To 7)
Dim SrcWksht As Worksheet
'Dim SrcWkshtName As String
Dim MonWksht As Worksheet
Dim strCntctDate As String
Dim strCntctMo As String


Set SrcWksht = ThisWorkbook.Sheets("Sheet1")

MonWksht.Name = SrcWksht.Name & " - Monthly"<---error

Any suggestions?



Maybe I didn't explain this clearly. I'm not trying to rename a sheet.
I'm trying to set the variable MonWksht = to an existing worksheet,
which uses the current worksheet's name plus "monthly". For example,
the workbook has a series of sheets named for people on staff. Barry,
Sam, Sue, etc. It also has a series of sheets named "Barry - Monthly",
Sam - Monthly", etc. The source sheet where the macro will get it's
data is in the "Barry" sheet. Then it will count certain codes by month
and put the totals in "Barry - Monthly". I want to set SrcWksht =
"Barry" and MonWksht = "Barry" plus "Monthly" so it knows which sheet
to put the data in. All the sheets already exist. Does that help?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
concatenate #N/A Bry Excel Discussion (Misc queries) 7 April 29th 23 03:42 AM
Concatenate() help Ayo Excel Discussion (Misc queries) 3 May 1st 09 04:45 AM
Concatenate CJ Excel Worksheet Functions 2 October 16th 06 11:07 AM
IF, IF, Concatenate? savvysam Excel Worksheet Functions 6 August 3rd 05 11:16 PM
I know how to concatenate ,can one de-concatenate to split date? QUICK BOOKS PROBLEM- New Users to Excel 1 July 26th 05 05:07 PM


All times are GMT +1. The time now is 03:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"