LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.misc
pm pm is offline
external usenet poster
 
Posts: 122
Default macro looping error

Sorry my last message was probably very confusing. I've worked on this all
afternoon trying to get the correct syntax.....This script works great...i
just need to tweak it a bit.....In each sheet for column D if the row/cell
includes the word TOTAL ..ex (18051-0707 Total) I want to select 18051, and
if it is the total row then extact the extended cost in column L of each
sheet....and put in Echosheet. Can you please help?

"JLatham" wrote:

Here's what I come up with. I was a bit confused as your sample code had a
title of RoundToZero and yet it does no such thing. But no matter...

Sub WorkThroughData()
Dim echoSheet As Worksheet
Dim ws As Worksheet
Dim colDRange As Range
Dim anyColDCell As Range
Dim newFormula As String

'get your Echo sheet into the
'workbook and then pick up
'here to work through the
'other sheets/data
Set echoSheet = Worksheets("Echo")
For Each ws In ThisWorkbook.Worksheets
If ws.Name < echoSheet.Name Then
Set colDRange = ws.Range("D1:" & _
ws.Range("D" & Rows.Count).End(xlUp).Address)
For Each anyColDCell In colDRange
If Not IsEmpty(anyColDCell) Then
'you're going to want to tweak
'this formula, probably using
'the row number of anyColDCell
'as anyColDCell.Row
newFormula = "=MID('" & ws.Name & _
"'!R[3]C[3],1,5)"
'put formula into next available
'cell in column A of Echo sheet
echoSheet.Range("A" & Rows.Count). _
End(xlUp).Offset(1, 0).FormulaR1C1 _
= newFormula
End If
Next ' individual cell loop
End If
Next ' worksheet loop end
'all done, do housekeeping
Set colDRange = Nothing
Set echoSheet = Nothing
End Sub

Hope this gets things moving for you.

"pm" wrote:

I have a spreadsheet that has 6 tabs and need to read the data in a specific
column (D) in each sheet...if the cell is not blank then store the data in a
new sheet....then go to next sheet and so on...i can't get my loop to
work....any suggestions?

This creates the new sheet:

Set NewSheet = Worksheets.Add
NewSheet.Name = "Echo"
Sheets("Echo").Select
Sheets("Echo").Move After:=Sheets("Store Ops")
Sheets("Apparel").Select

I want this to read data in each cell in column D for each sheet and if it's
not blank then write record to Echo sheet:

Sub RoundToZero()
For Each ws In Worksheets
dlr = Cells(Rows.Count, 1).End(xlUp).Row + 1
If ws.Name < ActiveSheet.Name Then
With ws
Cells(dlr, "d") = .Range("d2").Value
Next ws
End If
End Sub

This is the data i want to write to Echo sheet:

Sheets("Echo").Select
ActiveCell.FormulaR1C1 = "=MID(Janitorial!R[3]C[3],1,5)"
Sheets("Echo").Select

 
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
Looping Macro Jase Excel Discussion (Misc queries) 5 March 12th 08 09:08 PM
Macro looping endlessly Sandy Excel Worksheet Functions 6 May 10th 07 03:48 PM
Looping macro RK Excel Worksheet Functions 2 December 12th 06 11:29 PM
Looping a macro Sony Excel Discussion (Misc queries) 3 October 30th 06 11:52 AM
Macro looping problem. [email protected] Excel Discussion (Misc queries) 8 October 26th 06 02:44 PM


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