![]() |
Wheres the bug
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! |
Wheres the bug
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) "Catherine" wrote in message ... Hi gang! Here's my code Sub summary2() Application.ScreenUpdating = True Dim i As Integer Dim myVal As String On Error Resume Next Application.DisplayAlerts = False Worksheets("Summary").Delete Application.DisplayAlerts = True Worksheets.Add(Worksheets(1)).Name = "Summary" For i = Worksheets("Start").Index + 1 To Worksheets("End").Index - 1 myVal = Worksheets(i).Range("P13").Text 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 Next i Im getting a syntax error on ....If Left(myVal,2) = "F" Wheres the bug? Thanks! |
Wheres the bug
See reply to your previous post.
In article , Catherine wrote: Hi gang! Here's my code Sub summary2() Application.ScreenUpdating = True Dim i As Integer Dim myVal As String On Error Resume Next Application.DisplayAlerts = False Worksheets("Summary").Delete Application.DisplayAlerts = True Worksheets.Add(Worksheets(1)).Name = "Summary" For i = Worksheets("Start").Index + 1 To Worksheets("End").Index - 1 myVal = Worksheets(i).Range("P13").Text 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 Next i Im getting a syntax error on ....If Left(myVal,2) = "F" Wheres the bug? Thanks! |
Wheres the bug
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) "Bob Phillips" wrote in message ... 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) "Catherine" wrote in message ... Hi gang! Here's my code Sub summary2() Application.ScreenUpdating = True Dim i As Integer Dim myVal As String On Error Resume Next Application.DisplayAlerts = False Worksheets("Summary").Delete Application.DisplayAlerts = True Worksheets.Add(Worksheets(1)).Name = "Summary" For i = Worksheets("Start").Index + 1 To Worksheets("End").Index - 1 myVal = Worksheets(i).Range("P13").Text 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 Next i Im getting a syntax error on ....If Left(myVal,2) = "F" Wheres the bug? Thanks! |
Wheres the bug
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 , "Bob Phillips" wrote: 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 |
Wheres the bug
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 |
All times are GMT +1. The time now is 03:56 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com