View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ingeborg AV Ingeborg AV is offline
external usenet poster
 
Posts: 1
Default Copy between workbooks if statement is true

I have two workbooks: Prisliste.xls (price list) and faktura.xls (invoice).
In the invoice I want to just write id-numbers, and based on these
id-numbers, I want a macro to get the data from the price list.

In Prisliste.xls I have the following data:
Column A: id-number
Column B: name of book
Column D: price of book
Column E: price of book ex. taxes

In faktura.xls I have an area (cell B19 to D32), where I want the data
transferred. Names of books in column B, prices in column D.

I want to write id-numbers in the cells of column B, run a macro that
replaces the numbers with names, and inserts the prices.

How do I make the macro understand where to put the names and the prices?
What should I write instead of ActiveSheet.Range("B") ?

This is my code so far (I might be far off, or close to the solution):

Sub boknummer()

'nameing the area in use "tittel"
Dim tittel As Range
Set tittel = Range("B19:B32")

For Each Cell In tittel

If Cell.Value =
Workbooks("Prisliste.xls").Worksheets("priser").Ra nge("A2").Value Then
'checks if the id-number is the same as the first id-number of Prisliste.xls
ActiveSheet.Range("B") =
Workbooks("Prisliste.xls").Worksheets("priser").Ra nge("B2").Value 'inserts
the book name
ActiveSheet.Range("D") =
Workbooks("Prisliste.xls").Worksheets("priser").Ra nge("D2").Value 'inserts
the book price
End If

'checks the next id-number

If Cell.Value =
Workbooks("Prisliste.xls").Worksheets("priser").Ra nge("A3").Value Then
ActiveSheet.Range("B") =
Workbooks("Prisliste.xls").Worksheets("priser").Ra nge("B3").Value
ActiveSheet.Range("D") =
Workbooks("Prisliste.xls").Worksheets("priser").Ra nge("E3").Value
End If

'checks the other id-numbers, I excluded the code since it is
similar to the examples above.

Next

End Sub


Thanks for any suggestions, links etc

Ingeborg Altern Vedal