Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,089 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,801 people online right now. Registration is fast and FREE... Join Now!




[VB2005] Finding last cell in the column in excel

 
Reply to this topicStart new topic

[VB2005] Finding last cell in the column in excel

bellaelysium
20 Jun, 2008 - 01:22 AM
Post #1

New D.I.C Head
*

Joined: 8 Jun, 2008
Posts: 32

Is there any code where I can use VB 2005 to find the last cell of the specific column (used range)in Excel?

I am creating a chart using VB 2005 to plot in excel and the data will be random, so the last cell will not be fixed. But the first cell is not, but I'm still clueless on how to write that particular code.

There's one code in VBA which has the code:

CODE
ActiveSheet.Cells.SpecialCells(xlLastCell)



Does VB 2005 has the similar code like that?

I tried using VB object browser and help but to no avail.

Someone can give some guidance and I can figure out myself. Great thanks! Need to know urgently =)
User is offlineProfile CardPM
+Quote Post

bellaelysium
RE: [VB2005] Finding Last Cell In The Column In Excel
22 Jun, 2008 - 08:36 PM
Post #2

New D.I.C Head
*

Joined: 8 Jun, 2008
Posts: 32


I want to clarify..is End(Excel.XlDirection) the right function to find last used cell in that specific column?

Have been cracking my brain and looking thru threads in my weekend but still isnt getting anywhere.

here's the code I tried:
CODE

Dim rng As Excel.Range
Dim colNum As Integer

colNum = 2
rng = WSheet.Cells(WSheet.Rows.Count, colNum)._
End(Excel.XlDirection.xlDown)

With xlsAxisCategory.Item(Excel.XlAxisType.xlCategory)
                .HasTitle = True
                .AxisTitle.Characters.Text = "Time"
                .HasMajorGridlines = True
                .HasMinorGridlines = True
                .MinimumScale = 0.479166666666667
                .MaximumScale = rng.Value '0.486111111111111
                .MinorUnit = 0.000347222222222222
                .MajorUnit = 0.000694444444444444
                .Crosses = XlAxisCrosses.xlAxisCrossesAutomatic
                .ReversePlotOrder = False
                .ScaleType = XlScaleType.xlScaleLinear
                .TickLabels.Orientation = XlTickLabelOrientation._
xlTickLabelOrientationUpward

            End With


The whole graph's x-axis went hay wire.
I place the rng.value at ".MaximumScale = rng.Value '0.486111111111111"
And '0.486111111111111 is actually the value I enter initially which the graph work perfectly.

'0.486111111111111 refer to the last cell i select in the 2nd column "B" (time column), which is actually 11:40:00 and the excel convert it to 0.486111111111111.

But I want the program to select last cell itself instead of me selecting it.


I'm not sure if I am using the correct function.


I also tried this code:
CODE
rangEndTime = WSheet.UsedRange._
End(Excel.XlDirection.xlDown).Row

With xlsAxisCategory.Item(Excel.XlAxisType.xlCategory)

.MaximumScale = rangEndTime.ToString '0.486111111111111

End with



The graph still haywire as well.



I really need help. I notice that the topic has been read but no one reply.

Million thanks!
User is offlineProfile CardPM
+Quote Post

WayneSpangler
RE: [VB2005] Finding Last Cell In The Column In Excel
23 Jun, 2008 - 04:42 AM
Post #3

D.I.C Head
**

Joined: 22 Mar, 2008
Posts: 103



Thanked: 9 times
My Contributions
I don't have Excel but try this:
http://www.ozgrid.com/VBA/ExcelRanges.htm
User is offlineProfile CardPM
+Quote Post

bellaelysium
RE: [VB2005] Finding Last Cell In The Column In Excel
23 Jun, 2008 - 05:17 AM
Post #4

New D.I.C Head
*

Joined: 8 Jun, 2008
Posts: 32

QUOTE(WayneSpangler @ 23 Jun, 2008 - 05:42 AM) *

I don't have Excel but try this:
http://www.ozgrid.com/VBA/ExcelRanges.htm


yes i did...I already wrote the code on top... and have stated some problems I'm facing...

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 11:59PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month