VBA Question - Excel

jwwhite021

New Member
Joined
Feb 19, 2009
Messages
10
Hi,

My friend created an excel file using VBA so that I could manage my investments, there is a macro that I use to enter a transaction, it would take the details I enter, like ticker, number of shares sold and transfer that data into another excel tab. It has historically added the transaction at the bottom of the list e.g. row 21, then 22, then 23 etc, but for some reason it now enters it at the top and it is ruining this rather complex file.

When I click on debug, the following code is highlighted:
highestRef = Sheets("Trading ledger").Range(tradingLedgerCellStart).Offset(l, NbField + 4).Value

I have no idea what the above code is saying so I am hoping that one of your could a) translate and then b) suggest a potential new code?

Many thanks for your help.

John
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
2 things you can do to help us help you out.

(1) hover over the highlighted area and see what value has been given (if any) to 'highestref'
(2) search the project to see where else 'highestref' is mentioned.

I would guess that its supposed to be the next blank row but can't be sure without more info.

DP
 
Upvote 0
a) That means:
tradingLedgerCellStart is a cell address, or the name of a named range on the 'Trading Ledger' sheet
start at that cell and go down l rows and across (NbField + 4) columns, then assign the value of that cell to the highestRef variable.
b) There is no realistic way for us to suggest an alternative code given that we know nothing about how your sheets are laid out or what those variables represent. Clearly something has changed in your workbook (probably the insertion or deletion of some columns I would suspect).
 
Upvote 0
How are tradingLedgerCellStart, l and NbField assigned values and what are those values when you run your code?
 
Upvote 0
It sounds like to macro is working (although not with the desired output), so why does it highlight a particular row? Or is there an error which points you to this row?

If you hover your mouse over the variables (highestRef, tradingLedgerCellStart, l, NbField), you will see which values they are assigned. That might give you a clue on what is going wrong.
 
Upvote 0
Firstly, thank you for getting back to me,

The full code for this is as follows

'Assign a deal reference
highestRef = -1
For l = 1 To nbtrade - 1
If Sheets("Trading ledger").Range(tradingLedgerCellStart).Offset(l, NbField + 4).Value > highestRef Then
highestRef = Sheets("Trading ledger").Range(tradingLedgerCellStart).Offset(l, NbField + 4).Value
End If
Background - each transaction is assigned a deal reference, the text highlighted in red seems to be the error. When I hover over, I get the following results:
highestref=0,
TradingLedgerCell Start = A8
Offset = i=2, nbfield=8

So historically this code has transferred the data I would enter in one tab in to a row on another tab and assign a deal reference number.(which is reflected in the code above).

What would be useful is to correct the code above so that it assigns a reference greater than that last one by one, and then places the info below the last data row.

Hope this helps you, thanks again!

John
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,774
Members
452,353
Latest member
strainu

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