LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Reply to thread 'Syntax error on looping through each cell

Hi E-on,

Am Tue, 5 Jun 2012 13:34:59 +0000 schrieb E-on:

Sub Copytom()
Dim rng As Range, i As Long, ws As Worksheet, sh As Worksheet

For Each ws In Worksheets
On Error Resume Next
If sh.Name = "New" Then sh.Delete
If sh.Name < "New" Then
Set sh = Sheets.Add
sh.Name = "New"
End If
For i = 3 To 100
If ws.Cells(i, 5).Value = " Stockwell Motors" Then
ws.Range("F" & i & ":G" & i).Copy
Worksheets("New").Range("A" & _Rows.Count).End(xlUp).Offset(1, 0)
End If
Next
Next
End Sub


why you want to loop through 100 rows? You can filter and copy the
visible cells in sheet "New". What's the name of ws? In following code I
set ws = worksheets("Overview") - change it to your really name:

Sub Copytom()
Dim rng As Range, i As Long, ws As Worksheet
Dim sh As Worksheet, LRow As Long

On Error Resume Next
Set sh = Worksheets("New")
If Not sh Is Nothing Then
Application.DisplayAlerts = False
sh.Delete
Application.DisplayAlerts = False
End If

Set sh = Sheets.Add
sh.Name = "New"

Set ws = Worksheets("Overview")
With ws
..Range("A2").AutoFilter Field:=5, Criteria1:= _
"Stockwell Motors"
LRow = .Cells(.Rows.Count, 1).End(xlUp).Row
..Range("F3:G" & LRow).Copy _
Worksheets("New").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
..AutoFilterMode = False
End With

End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
 
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
Why, when I post a thread, can I not reply to a response using thereply button? ChipButtyMan Excel Programming 1 October 25th 08 12:16 AM
Can't open the link to a reply to a thread I posted RkyMtn New Users to Excel 1 September 12th 08 08:10 AM
Syntax for looping through rows and columns in Excel Curious[_2_] Excel Programming 6 August 7th 07 09:55 PM
what is 'too many different cell formats' reply? tommy Excel Discussion (Misc queries) 4 December 17th 04 06:23 AM
syntax for relative cell change and looping BwanaP Excel Programming 1 September 27th 03 03:36 PM


All times are GMT +1. The time now is 03:42 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"