LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Batch Processing Macro

This works too! Thanks for everything guys!!
Ryan---

--
RyGuy


"Dave Peterson" wrote:

I'm coming late to the party, but here's another one to try:

Option Explicit
Sub testme01()

Dim tempWkbk As Workbook

Dim myNames() As String
Dim fCtr As Long
Dim myFile As String
Dim myPath As String
Dim lastrow As Long
Dim c As Variant

'change to point at the folder to check
myPath = "C:\Ryan"
If Right(myPath, 1) < "\" Then
myPath = myPath & "\"
End If

myFile = Dir(myPath & "*.xls")
If myFile = "" Then
MsgBox "no files found"
Exit Sub
End If

'get the list of files
fCtr = 0
Do While myFile < ""
fCtr = fCtr + 1
ReDim Preserve myNames(1 To fCtr)
myNames(fCtr) = myFile
myFile = Dir()
Loop

If fCtr 0 Then
For fCtr = LBound(myNames) To UBound(myNames)
Set tempWkbk = Workbooks.Open(Filename:=myPath & myNames(fCtr))

'what worksheet in that tempwkbk gets worked on?
'I used the first (leftmost) worksheet
With tempWkbk.Worksheets(1)
.Rows(1).Font.Bold = True
lastrow = .Cells(.Rows.Count, "F").End(xlUp).Row

For Each c In .Range("F2:F" & lastrow)
If c.Value < "" Then
c.Offset(, 20).FormulaR1C1 _
= "=IF(RC[-20]<"""",RC[-17]*RC[-3])"
End If
Next c
End With

tempWkbk.Close savechanges:=True
Next fCtr

End If

End Sub


ryguy7272 wrote:

Thanks T Lavedas! The code looks tight, but the still seems to be a problem
somewhere. I can't see it. Can you see the issue? The error is he
For Each c In Range("F2:F" & lastrow)

Message is:
Method Range of object_Global Failed

Code is:
Option Explicit
Sub testme01()

Dim tempWkbk As Workbook

Dim myNames() As String
Dim fCtr As Long
Dim myFile As String
Dim myPath As String
Dim lastrow As Long
Dim c As Variant

'change to point at the folder to check
myPath = "C:\Ryan"
If Right(myPath, 1) < "\" Then
myPath = myPath & "\"
End If

myFile = Dir(myPath & "*.xls")
If myFile = "" Then
MsgBox "no files found"
Exit Sub
End If

'get the list of files
fCtr = 0
Do While myFile < ""
fCtr = fCtr + 1
ReDim Preserve myNames(1 To fCtr)
myNames(fCtr) = myFile
myFile = Dir()
Loop

If fCtr 0 Then

For fCtr = LBound(myNames) To UBound(myNames)
Set tempWkbk = Workbooks.Open(Filename:=myPath & myNames(fCtr))

Rows("1:1").Select
Selection.Font.Bold = True

For Each c In Range("F2:F" & lastrow)
If c.Value < "" Then
c.Offset(, 20).Value = "=IF(RC[-20]<"""",RC[-17]*RC[-3])"
End If
Next c
tempWkbk.Close savechanges:=True
Next fCtr

End If

End Sub

Regards,
Ryan--

--
RyGuy

"T Lavedas" wrote:

On May 6, 1:36 pm, ryguy7272
wrote:
Here is my code now:
For fCtr = LBound(myNames) To UBound(myNames)
Set tempWkbk = Workbooks.Open(Filename:=myPath & myNames(fCtr))

lastrow = Cells(Rows.Count, "F").End(xlUp).Row
For Each c In Range("F2:F" & lastrow)
If c.Value < "" Then
c.Offset(, 20).Value = "=IF(RC[-20]<"""",RC[-17]*RC[-3])"
Next c

'Columns("B:B").Select
'Selection.Insert Shift:=xlToRight
tempWkbk.Close savechanges:=True
Next fCtr

I keep getting a Next Without For error. this line seems to be the culprit:
Next c

Not sure why though...

Sorry Gary, I recorded a macro and got a slightly different value
(requirements changed) as seen above. It just seemed easier to use this than
to use the value that you sent to me.

--
RyGuy


The IF block within the innermost FOR is not closed.

For Each c In Range("F2:F" & lastrow)
If c.Value < "" Then
c.Offset(, 20).Value = "=IF(RC[-20]<"""",RC[-17]*RC[-3])"
end if
Next c

Indenting helps avoid such problems.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/


--

Dave Peterson



 
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
Background Batch Processing AlexTanlimco Excel Programming 0 March 1st 08 12:08 AM
Batch File drag-n-drop processing. Beav Excel Programming 3 January 25th 07 04:00 PM
Batch Processing macro for excel Brian Excel Programming 3 October 26th 06 08:35 PM
Help finding a "batch processing" technique for a userform??? WillRn Excel Programming 1 July 27th 05 02:59 PM
Open Batch File For Processing Chuckles123[_79_] Excel Programming 4 July 15th 05 01:43 PM


All times are GMT +1. The time now is 10:34 PM.

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"