Wheres the bug

C

Catherine

Hi gang
Here's my cod
Sub summary2(

Application.ScreenUpdating = Tru
Dim i As Intege
Dim myVal As Strin
On Error Resume Nex
Application.DisplayAlerts = Fals
Worksheets("Summary").Delet
Application.DisplayAlerts = Tru
Worksheets.Add(Worksheets(1)).Name = "Summary
For i = Worksheets("Start").Index + 1 To Worksheets("End").Index -
myVal = Worksheets(i).Range("P13").Tex
If Left(myVal,2) = "F
Then Worksheets(i).Selec
Range("P10:p38").Cop
Worksheets("Summary").Selec
Range("IV1").End(xlToLeft)(1, 2).Selec
Selection.PasteSpecial Paste:=xlPasteValue
Selection.PasteSpecial Paste:=xlPasteFormat
'End I
Next

Im getting a syntax error on ....If Left(myVal,2) = "F
Wheres the bug

Thanks!
 
B

Bob Phillips

If needs a Then

If Left(myVal,2) = "F" Then
Worksheets(i).Select
Range("P10:p38").Copy
Worksheets("Summary").Select
Range("IV1").End(xlToLeft)(1, 2).Select
Selection.PasteSpecial Paste:=xlPasteValues
Selection.PasteSpecial Paste:=xlPasteFormats
End If


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
B

Bob Phillips

Also testing the first two characters of a variable against a single
character does not seem smart. It will only succeed if myVal = F, in which
case you don't need the Left

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
J

JE McGimpsey

Looking at it again, this might be how I'd do it:


Public Sub Summary2()
Const sFNAME As String = "Summary"
Dim rDest As Range
Dim i As Long

With Application
.ScreenUpdating = False
.DisplayAlerts = False
On Error Resume Next
Worksheets(sFNAME).Delete
On Error GoTo 0
.DisplayAlerts = True
With Worksheets.Add(Worksheets(1))
.Name = sFNAME
Set rDest = .Range("A1")
End With
For i = Worksheets("Start").Index + 1 To _
Worksheets("End").Index - 1
With Worksheets(i)
If Left(.Range("P13").Text, 1) = "F" Then
.Range("P10:p38").Copy
With rDest
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
End With
Set rDest = rDest(1, 2)
End If
End With
Next i
.ScreenUpdating = True
End With
End Sub




IIn article <[email protected]>,
 
C

Catherine

Thanks for all of the response
If Left(.Range("P13").Text, 1) = "F" The

Im new to programming and dont follow all the statement. The contents of p13 is a concatenation that my user is using. The second place (F) are the transaction that should be included in the summary. With your statement, how is it evaluated if there is an F some where else in the cell contents
Thank
Cat
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top