lastrow value is nil

rdev

Active Member
Joined
Dec 3, 2007
Messages
273
Please advise why the variable 'lastrow' is storing a value of 0 when there are data up to row 100 in column A

Sub usingFind()
Dim ms As Worksheet
Dim lastrow As Long, i As Long, c
Dim myCell As Range
Set ms = Sheets("mathew")
lastrow = ms.Range("A" & Rows.Count).End(xlUp).Row
x = 2
y = 3

c = ms.Cells(x, y).Value
u = ms.Cells(x, y).Offset(0, -1).Value
If u = "Purchase of goods" Then u1 = "Sales of goods"
If u = "Sales of goods" Then u1 = "Purchase of goods"
Set myCell = ms.Range("A1:A" & 1000).Find(What:=c, LookIn:=xlValues)

If Not myCell Is Nothing And myCell.Offset(0, 1).Value = u1 And _
myCell.Offset(0, 2).Value = c Then
Cells(x, 5).Value = c
Cells(x, 5).Value = myCell.Offset(0, 3).Value
myCell.Offset(0, 4).Value = Cells(x, 1).Value
myCell.Offset(0, 4).Value = Cells(x, 1).Value

End If
Exit Sub
End Sub
 
Hi thanks, this is the easiest route to go ,
No there will be multiple transaction between A and B , but the only distinguishing criteria would be in column E I have inserted; a purchase by one company would be a sale in another company , so there should be a formula in column E to insert "Sales of goods" if there is a "Purchase of goods" in B and vice versa
Please help me to adapt , the file
Data2.xlsm - Google Drive
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
In the examples you've posted so far, a sale from A to B is matched to a purchase by B from A even though the amounts don't match.

So if you have, say, three sales A to B, and three purchases B from A, how will you know which sale is related to which purchase? Even worse, what if you have three sales A to B and four purchases B from A?

What is the end goal here?
 
Upvote 0
No there will only be one sale from A and reciprocally 1 purchase of B from A
There can be another relationship linking A and B . For example A owes B and reciprocally B will show that it owes to A
By inserting a column E , we'll need a formula if B2 is "Purchase of Goods" then E2 would be "Sales of goods"
If B2 show Owed to , E2 should show 'receivable from' ; we will need then integrate column E in the sumifs with criteria in column B
 
Upvote 0
So perhaps something like this:

F2: =SUMIFS($D$2:$D$10,$A$2:$A$10,C2,$C$2:$C$10,A2,$B$2:$B$10,VLOOKUP(B2,TableOfOpposites,2,))


Excel 2010
ABCDEF
1CompanyTransactionTransaction PartyAmountCounter Amount
2AlpaPurchase of goodsSilicon135,000270,000
3TonySales of goodsCinbata12,000-
4AlpaSales of goodsNaturo167,000167,000
5AlpaSales of goodsCinbata78,00080,000
6SiliconSales of goodsAlpa270,000135,000
7AlpaOwed toNaturo777,000888,000
8NaturoPurchase of goodsAlpa167,000167,000
9CinbataPurchase of goodsAlpa80,00078,000
10NaturoReceivable fromAlpa888,000777,000
11
12TableOfOpposites
13Purchase of goodsSales of goods
14Owed toReceivable from
15Sales of goodsPurchase of goods
16Receivable fromOwed to
mathew
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top