Alright, below is the code I'm using. If "C1" is the only cell in column "C" that has info the code freaks out and calulates all the way to the bottom (at least I think so). Does anyone know how to avoid this? Also, column "C" will obviously have different lentghs of data, it won't always just be one. Do I essentially need to have a header of some sort to always have more than one cell with a value in it? What if I don't have any values, other than the header, do I then have to write code to bypass it all together? Sorry if the is too many "ifs".
Add Formula to Bottom of Column
-
-
-
Re: Dim As Long Won't Work With One Cell?
I'm trying to determine how long Column "C" is so the code knows how many rows to put the formula in.
-
Re: Dim As Long Won't Work With One Cell?
Never go down buddy, always up - Try this line of code
[vb]
Range("c65536").End(xlUp).Select
[/vb][vb]
Sub test_IT()
' written by jack in the uk - for http://www.OzGrid.com
' Our WEB SITE http://www.excel-it.comDim myCell As Excel.Range
Dim myRow As Long
Set myCell = Range("c65536").End(xlUp)
myRow = myCell.Row
MsgBox myRow
End Sub
[/vb]
jiuk -
Re: Dim As Long Won't Work With One Cell?
Quote from Foxxy1I'm trying to determine how long Column "C" is so the code knows how many rows to put the formula in.
The code above will give You the last cell so its C1 from that cell reference, can not tell how Your going about this without Your codes in full but should be doable from herejiuk
-
-
Re: Dim As Long Won't Work With One Cell?
Does this help more?
[vb]
Sub test_IT_V2()
' written by jack in the uk - for http://www.OzGrid.com
' Our WEB SITE http://www.excel-it.comDim myCell_START As Excel.Range
Dim myCell_END As Excel.Range
Dim myRow_START As Long
Dim myrow_FINSIH As Long
Dim myCountRows As Long
Dim myRange As Excel.RangeSet myCell_START = Range("c1")
Set myCell_finish = Range("c65536")
myRowCount = myCell_finish.End(xlUp).Row - myCell_START.Row
MsgBox myRowCount
'
Set myRange = Union(myCell_START.End(xlDown), myCell_finish.End(xlUp))
MsgBox myRange.Address(False, False)
theEnd:
Set myCell_START = Nothing
Set myCell_finish = Nothing
Set myRange = Nothing
Exit Sub
End Sub
[/vb]
jiuk -
Re: Dim As Long Won't Work With One Cell?
Quote from Foxxy1I'm trying to determine how long Column "C" is so the code knows how many rows to put the formula in.
As well as Jacks suggestion - for more help See this link.
-
-
Re: Add Formula to Bottom of Column
Good Stuff guys, thanks for the help.
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!