View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
kfguardian kfguardian is offline
external usenet poster
 
Posts: 5
Default Need help evaluating cells in another workbook in macro

That works great, Thanks! Is there a way to do it without requiring the other
workbook to be open (that is frmInputData.xls)?

Also, I had to comment out the line "Set wkb1 = ActiveWorkboook." I think
it already assumes you are talking about the active sheet unless you say
otherwise?!

"Smallweed" wrote:

Easiest to use object variables. The following example will go through A1:Z1
on Sheet1 of the second workbook, filling 5 into equivalent cells on Sheet1
of the activeworkbook if the cell has A in it:

Dim rng As Range
Dim rng1 As Range
Dim rng2 As Range
Dim wkb1 As Workbook
Dim wkb2 As Workbook
Dim wks1 As Worksheet
Dim wks2 As Worksheet
Set wkb1 = ActiveWorkboook
Set wks1 = wkb1.Worksheets("Sheet1")
Set rng1 = wks1.Range("A1")
Set wkb2 = Workbooks("frmInputData.xls")
Set wks2 = wkb2.Worksheets("Sheet1")
Set rng2 = wks2.Range("A1:Z1")
For Each rng In rng2
If rng.Value = "A" Then
rng1.Value = 5
End If
Set rng1 = rng1.Offset(1,0)
Next rng