View Full Version : Solved: Ranges are the Worst...
magelan
01-31-2013, 11:41 AM
So, the age old question of "How do I get the Range I want, because ranges do not work logically or simply".
I'm trying to grab the last row of Column C but of course this doesnt work [because ranges are a headache to work with]
With ActiveSheet
listLength = .Cells(.Rows.Count, "C").End(xlUp).Row
End With
cellsRange = Range("C2:C" & listLength)
i also tried
With ActiveSheet
listLength = .Cells(.Rows.Count, "C").End(xlUp).Row
cellsRange = Range("C2", Cells(.Rows.Count, "C").End(xlUp))
end with
magelan
01-31-2013, 11:43 AM
Apparently I had forgotten to put "set" in there...
Nevermind.
sub M_snb()
lastcell=sheets(1).cells(rows.count,3).end(xlup).address
end sub
magelan
02-18-2013, 10:00 AM
Heres another one...
Dim destinationRange As Range
Range("J9:Q9").Select
Set destinationRange = Range(Selection, Selection.End(xlDown))
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & inputfile, Destination:=Range("$A$8"))
.Name = "inputme"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
'Fill in Formulas for Data
Application.Goto Reference:="R9C10"
Range(Selection, Selection.End(xlToRight)).Select
Selection.AutoFill Destination:=destinationRange
Of course, the code decides to fill THE ENTIRE WORKBOOK rather than just the used cells.
What i'm trying to accomplish is to autofill from J9:Q9 to J[end]:Q[end]
Look in the VBA helpfiles, lemma 'currentregion'.
PS. I hope you realise a worksheet is a range, a row is a range, a column is a range, a cell is a range....
Aussiebear
02-18-2013, 04:47 PM
"... because ranges do not work logically or simply".
Then you won't like excel. As snb has indicated from a single cell to multiple combinations of cells they are all ranges.
[Quote]I'm trying to grab the last row of Column C but of course this doesnt work [because ranges are a headache to work with]
Have a good look at naming your ranges, and creating dynamic ranges.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.