LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default For Each c In Range... is slow

This works but is a bit clunky and a little slow.

With sheet Reg:
Columns A, B, C is Name, Info1, Info2 (a person & two info bits per row)
Columns D, E, F, G, H, I are Sheet1, Sheet2, Sheet3 etc. actual sheet names in the workbook, just using six here, could be ~15.

If any of the cells in the Sheet Name Header columns have an "X" then the column A, B, C data on that row is copied to the sheet named in the Header of that column.

I have set OneRng to include D2 to I- as far down as column A info goes.
Then a For Each / Next offsetting from each "X" to copy the A B C info of that row and paste in the sheet name of that column.

I'm guessing the search method for looking across the OneRng is not very efficient using this approach.

Got a smoother idea, please?

Howard


Sub Header_Sheet()
Dim OneRng As Range
Dim sheetTo As String
Dim c As Range
Dim aRow As Long, aCol As Long


Set OneRng = Sheets("Reg").Range("D2:I" & Cells(Rows.Count, "A").End(xlUp).Row)
Application.ScreenUpdating = False

For Each c In OneRng
aRow = c.Row - 1
aCol = c.Column - 1

sheetTo = c.Offset(-aRow, 0).Value

If c = "X" Then
c.Offset(, -aCol).Resize(1, 3).Copy Sheets(sheetTo).Range("A" & Rows.Count).End(xlUp)(2)
End If

Next 'c
Application.ScreenUpdating = True
End Sub
 
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
SUMPRODUCT with date range running slow Chipperzs Excel Discussion (Misc queries) 1 January 12th 12 01:09 PM
Range.Find gets slow vbapro Excel Programming 19 April 18th 08 03:05 PM
Looping through Range...Slow Craig M Excel Programming 5 September 7th 06 08:18 AM
Any thoughts - VBA Slow Down with Range.Clear Command Paul Fenton Excel Programming 5 February 17th 06 02:16 PM
Problem with Slow ReCalculation of Dynamic Range Using OFFSET Kris_Wright_77 Excel Worksheet Functions 2 November 18th 05 10:18 AM


All times are GMT +1. The time now is 06:12 AM.

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

About Us

"It's about Microsoft Excel"