Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default Referencing two types of sheets - I get Error HELP!!

I am referencing two types of named sheet(s) in a work book. One named with
_Bal and the others named _Trial but I get error. What am I doing wrong. All
help totally appreciated. THanks

Sub T_Bal()
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In Worksheets
If InStr(1, ws.Name, "_Bal") Then
With ws
.Range("g35").Value = .Range("g40").Value
With .Range("g23")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g36").Value
End With
With .Range("g30")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g57").Value
End With
.Range("g57").Value = 0
End With
ElseIf InStr(1, ws.Name, "_Trial") Then
With ws
.Range ("g23")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g36").Value
End With
End If
Next
Application.ScreenUpdating = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Referencing two types of sheets - I get Error HELP!!

Can you locate the line the error occurs on and what the error is for us?

--
Rick (MVP - Excel)


"Yossy" wrote in message
...
I am referencing two types of named sheet(s) in a work book. One named with
_Bal and the others named _Trial but I get error. What am I doing wrong.
All
help totally appreciated. THanks

Sub T_Bal()
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In Worksheets
If InStr(1, ws.Name, "_Bal") Then
With ws
.Range("g35").Value = .Range("g40").Value
With .Range("g23")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g36").Value
End With
With .Range("g30")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g57").Value
End With
.Range("g57").Value = 0
End With
ElseIf InStr(1, ws.Name, "_Trial") Then
With ws
.Range ("g23")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g36").Value
End With
End If
Next
Application.ScreenUpdating = True
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default Referencing two types of sheets - I get Error HELP!!

it highlights the . Range within this code and gave error as invalid use of
property.

ElseIf InStr(1, ws.Name, "_Trial") Then
With ws
.Range ("g23") ' it highlights the .Range here


"Rick Rothstein" wrote:

Can you locate the line the error occurs on and what the error is for us?

--
Rick (MVP - Excel)


"Yossy" wrote in message
...
I am referencing two types of named sheet(s) in a work book. One named with
_Bal and the others named _Trial but I get error. What am I doing wrong.
All
help totally appreciated. THanks

Sub T_Bal()
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In Worksheets
If InStr(1, ws.Name, "_Bal") Then
With ws
.Range("g35").Value = .Range("g40").Value
With .Range("g23")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g36").Value
End With
With .Range("g30")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g57").Value
End With
.Range("g57").Value = 0
End With
ElseIf InStr(1, ws.Name, "_Trial") Then
With ws
.Range ("g23")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g36").Value
End With
End If
Next
Application.ScreenUpdating = True
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Referencing two types of sheets - I get Error HELP!!

I think Dave has given you what the problem is. Right after the 'With ws'
you have .Range("g23") on the line all by itself... you aren't doing
anything with it. You probably meant the code to look like this (mirroring
how you handled the code structure in the "Then" section)...

With ws
With .Range("g23")
.....

instead of how you posted it.

--
Rick (MVP - Excel)


"Yossy" wrote in message
...
it highlights the . Range within this code and gave error as invalid use
of
property.

ElseIf InStr(1, ws.Name, "_Trial") Then
With ws
.Range ("g23") ' it highlights the .Range here


"Rick Rothstein" wrote:

Can you locate the line the error occurs on and what the error is for us?

--
Rick (MVP - Excel)


"Yossy" wrote in message
...
I am referencing two types of named sheet(s) in a work book. One named
with
_Bal and the others named _Trial but I get error. What am I doing
wrong.
All
help totally appreciated. THanks

Sub T_Bal()
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In Worksheets
If InStr(1, ws.Name, "_Bal") Then
With ws
.Range("g35").Value = .Range("g40").Value
With .Range("g23")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g36").Value
End With
With .Range("g30")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g57").Value
End With
.Range("g57").Value = 0
End With
ElseIf InStr(1, ws.Name, "_Trial") Then
With ws
.Range ("g23")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g36").Value
End With
End If
Next
Application.ScreenUpdating = True
End Sub




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Referencing two types of sheets - I get Error HELP!!

Notice that you have "with ws" and "with .range("G23")" in the top portion of
the code.

You don't have that in the second portion:

With ws
.Range ("g23")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g36").Value
End With

So maybe:

With ws
with .Range("g23")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g36").Value
end with
End With

Yossy wrote:

I am referencing two types of named sheet(s) in a work book. One named with
_Bal and the others named _Trial but I get error. What am I doing wrong. All
help totally appreciated. THanks

Sub T_Bal()
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In Worksheets
If InStr(1, ws.Name, "_Bal") Then
With ws
.Range("g35").Value = .Range("g40").Value
With .Range("g23")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g36").Value
End With
With .Range("g30")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g57").Value
End With
.Range("g57").Value = 0
End With
ElseIf InStr(1, ws.Name, "_Trial") Then
With ws
.Range ("g23")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g36").Value
End With
End If
Next
Application.ScreenUpdating = True
End Sub


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default Referencing two types of sheets - I get Error HELP!!

Thanks to all, added the with and end with and it works. Thankssssss

"Dave Peterson" wrote:

Notice that you have "with ws" and "with .range("G23")" in the top portion of
the code.

You don't have that in the second portion:

With ws
.Range ("g23")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g36").Value
End With

So maybe:

With ws
with .Range("g23")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g36").Value
end with
End With

Yossy wrote:

I am referencing two types of named sheet(s) in a work book. One named with
_Bal and the others named _Trial but I get error. What am I doing wrong. All
help totally appreciated. THanks

Sub T_Bal()
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In Worksheets
If InStr(1, ws.Name, "_Bal") Then
With ws
.Range("g35").Value = .Range("g40").Value
With .Range("g23")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g36").Value
End With
With .Range("g30")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g57").Value
End With
.Range("g57").Value = 0
End With
ElseIf InStr(1, ws.Name, "_Trial") Then
With ws
.Range ("g23")
formStr = .Formula
.Formula = formStr & "+" & ws.Range("g36").Value
End With
End If
Next
Application.ScreenUpdating = True
End Sub


--

Dave Peterson

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
error bars types Office_user Charts and Charting in Excel 1 January 11th 10 12:44 PM
error bar types Office_user Charts and Charting in Excel 1 January 10th 10 06:47 PM
Excel 2007 error "some chart types cannot be combined with other chart types. Select a different chart types" roadsidetree Charts and Charting in Excel 15 June 2nd 09 10:53 AM
What does ISERROR look at besides the 7 Error Types? Bob Excel Worksheet Functions 5 November 17th 06 06:27 PM
Error types Darin Kramer Excel Programming 2 March 25th 05 07:39 PM


All times are GMT +1. The time now is 07:24 PM.

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"