Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default calculating values depending on columns in different wkbooks.

wkbk1
wkbk2
A B C
H K
MON BAL NEW CURR RATE
USD 786 CHF 0.89
EUR 8976 GBP 1.99
GBP 98765 EUR 0.78
CHF 89798
EUR 7765
GBP 98876
CHF 654
need help please.
I have 2 workbooks. for each cell in column A.rowx, check if value is equal
to any cell wkbk2 column F. if so wkbk1 column c = column b.rowx * column g
in wbk2. Hope this makes sense. I have tried to explain as simply as I can.
want to use a macro tied to a sub to do this just dont know enough vba to do
it.


-
Lindy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default calculating values depending on columns in different wkbooks.

Change sheet names as required


Sub GetBook2()

filetoopen = Application _
.GetOpenFilename("Excel Files (*.xls), *.xls")
If filetoopen = False Then
MsgBox ("Cannot Open File - Exiting Macro")
Exit Sub
End If

bk2 = Workbooks.Open(Filename:=filetoopen)
With ThisWorkbook.Sheets("Sheet1")
RowCount = 1
Do While .Range("A" & RowCount) < ""
MON = .Range("A" & RowCount)
With bk2.Sheets("Sheet1")
Set c = .Columns("F").Find(what:=MON, LookIn:=xlValues,
lookat:=xlWhole)
End With

If Not c Is Nothing Then
.Range("C" & RowCount) = .Range("B" & RowCount) * c.Offset(0, 1)
End If

RowCount = 1 = RowCount = 1 + 1
Loop
End With
bk2.Close savechanges:=False
End Sub

"Lindy" wrote:

wkbk1
wkbk2
A B C
H K
MON BAL NEW CURR RATE
USD 786 CHF 0.89
EUR 8976 GBP 1.99
GBP 98765 EUR 0.78
CHF 89798
EUR 7765
GBP 98876
CHF 654
need help please.
I have 2 workbooks. for each cell in column A.rowx, check if value is equal
to any cell wkbk2 column F. if so wkbk1 column c = column b.rowx * column g
in wbk2. Hope this makes sense. I have tried to explain as simply as I can.
want to use a macro tied to a sub to do this just dont know enough vba to do
it.


-
Lindy

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default calculating values depending on columns in different wkbooks.

Thks Joel

The first part works in opening the rates workbook, the second part gives me
a Run-time error 1004: Application-defined or object-defined error when it
gets to the line Do While .Range("CU" & RowCount) < ""

my code is as follows:

Set bk2 = Workbooks.Open(Filename:=fileToOpen)
With ThisWorkbook.Sheets("fdbpre")
RowCount = RowCount + 1
Do While .Range("CU" & RowCount) < ""
MON = .Range("CU" & RowCount)
With bk2.Sheets("Sheet1")
Set c = .Columns("A").Find(what:=MON, LookIn:=xlValues, lookat:=xlWhole)

End With

If Not c Is Nothing Then
.Range("EG" & RowCount) = .Range("CB" & RowCount) * c.Offset(0, 1)
End If

RowCount = 1 = RowCount = 1 + 1
Loop
End With
bk2.Close savechanges:=False
End Sub






--
Lindy


"Joel" wrote:

Change sheet names as required


Sub GetBook2()

filetoopen = Application _
.GetOpenFilename("Excel Files (*.xls), *.xls")
If filetoopen = False Then
MsgBox ("Cannot Open File - Exiting Macro")
Exit Sub
End If

bk2 = Workbooks.Open(Filename:=filetoopen)
With ThisWorkbook.Sheets("Sheet1")
RowCount = 1
Do While .Range("A" & RowCount) < ""
MON = .Range("A" & RowCount)
With bk2.Sheets("Sheet1")
Set c = .Columns("F").Find(what:=MON, LookIn:=xlValues,
lookat:=xlWhole)
End With

If Not c Is Nothing Then
.Range("C" & RowCount) = .Range("B" & RowCount) * c.Offset(0, 1)
End If

RowCount = 1 = RowCount = 1 + 1
Loop
End With
bk2.Close savechanges:=False
End Sub

"Lindy" wrote:

wkbk1
wkbk2
A B C
H K
MON BAL NEW CURR RATE
USD 786 CHF 0.89
EUR 8976 GBP 1.99
GBP 98765 EUR 0.78
CHF 89798
EUR 7765
GBP 98876
CHF 654
need help please.
I have 2 workbooks. for each cell in column A.rowx, check if value is equal
to any cell wkbk2 column F. if so wkbk1 column c = column b.rowx * column g
in wbk2. Hope this makes sense. I have tried to explain as simply as I can.
want to use a macro tied to a sub to do this just dont know enough vba to do
it.


-
Lindy

Reply
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
Calculating values in two columns based on a variable Alex Excel Discussion (Misc queries) 3 January 23rd 07 07:18 PM
calculating different percentages depending on amount pgruening Excel Discussion (Misc queries) 6 October 24th 05 05:57 PM
same chg in mult wkbooks svoynic48 Excel Discussion (Misc queries) 0 September 2nd 05 04:59 PM
Protect Rows depending on Values in Particular Columns [email protected] Excel Programming 0 July 14th 05 01:11 PM
Calculating totals depending on cell value Gary Paris Excel Programming 5 December 24th 04 10:34 PM


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