PC Review


Reply
Thread Tools Rate Thread

calculating values depending on columns in different wkbooks.

 
 
Lindy
Guest
Posts: n/a
 
      22nd Oct 2008
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 With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      22nd Oct 2008
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 With Quote
 
Lindy
Guest
Posts: n/a
 
      23rd Oct 2008
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculating values in two columns based on a variable Alex Microsoft Excel Misc 3 23rd Jan 2007 07:18 PM
calculating different percentages depending on amount pgruening Microsoft Excel Misc 6 24th Oct 2005 05:57 PM
Protect Rows depending on Values in Particular Columns singh352@hotmail.com Microsoft Excel Discussion 2 17th Jul 2005 07:11 AM
Protect Rows depending on Values in Particular Columns singh352@hotmail.com Microsoft Excel Programming 0 14th Jul 2005 01:11 PM
Calculating totals depending on cell value Gary Paris Microsoft Excel Programming 5 24th Dec 2004 10:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:57 AM.