donohara1
asked on
identifying last value in a row.
I have a VBA app (Excel), in which I need to identy the column notation (A, B,...) of the last value in a row. (I need to then insert that value in a subsiquent formula.) I already know which row to test on.
I would go to specific row and then determione the column notation value (lacall).
Then I would do a copy&paste operation as such:
SourceSh.Range(lacall & (958 + ioffset) & "." & lacall & (963 + ioffset)).Copy
r.Offset(0, 63).PasteSpecial xlPasteValues, , , True
Curently I retrieve LACALL from the user's workbook entry. Would be better If I figure it out.
Thanks
Don OHara
I would go to specific row and then determione the column notation value (lacall).
Then I would do a copy&paste operation as such:
SourceSh.Range(lacall & (958 + ioffset) & "." & lacall & (963 + ioffset)).Copy
r.Offset(0, 63).PasteSpecial xlPasteValues, , , True
Curently I retrieve LACALL from the user's workbook entry. Would be better If I figure it out.
Thanks
Don OHara
Is the range operator in your location '.'? - if not you may need to change it to a ':' in the example copy you give.
@andrewssd3 - is there a partcular reason you declare as Excel.Range as opposed to just Range?
Yes - it's really just a habit, but I have done a lot of developing of cross-product applications, where I had references say to Word and Excel in the same project. Then it's sometimes essential to differentiate - Range would be one of those, as both Word and Excel have Range objects. I just tend to do it all the time now, as it saves trouble later if the code need to be used in a cross-product context.
ASKER
DEMO Code
Dim THisRow As Range
Dim GetLastColLetter As String
...
Set Sourcewb = Workbooks.Open(filepath & Filename, False) (This works - DOH)
...
Set SourceSh = Sourcewb.Sheets("Agg Perf History")
THisRow = SourceSh.Range("a61:aaa61" )
lacall = GetLastColLetter(THisRow)
MsgBox "lacall is: " & lacall
------------
When I run this, I get 'Compile Error'
AS you can see, I am looking at the row a61 to ea61 and want to find the column ID for the latest value. Is there a simple code to select this row and call the function so I can use the column ID in a number of copy&paste commands.
Thanks,
Don
Dim THisRow As Range
Dim GetLastColLetter As String
...
Set Sourcewb = Workbooks.Open(filepath & Filename, False) (This works - DOH)
...
Set SourceSh = Sourcewb.Sheets("Agg Perf History")
THisRow = SourceSh.Range("a61:aaa61"
lacall = GetLastColLetter(THisRow)
MsgBox "lacall is: " & lacall
------------
When I run this, I get 'Compile Error'
AS you can see, I am looking at the row a61 to ea61 and want to find the column ID for the latest value. Is there a simple code to select this row and call the function so I can use the column ID in a number of copy&paste commands.
Thanks,
Don
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks to both of you.
Open in new window