Consulting

Results 1 to 6 of 6

Thread: Solved: Ranges are the Worst...

  1. #1

    Solved: Ranges are the Worst...

    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]

    [vba]
    With ActiveSheet
    listLength = .Cells(.Rows.Count, "C").End(xlUp).Row
    End With

    cellsRange = Range("C2:C" & listLength)
    [/vba]

    i also tried
    [vba]
    With ActiveSheet
    listLength = .Cells(.Rows.Count, "C").End(xlUp).Row


    cellsRange = Range("C2", Cells(.Rows.Count, "C").End(xlUp))

    end with
    [/vba]
    Last edited by Aussiebear; 02-18-2013 at 04:42 PM. Reason: Corrected the tags surrounding the code

  2. #2
    Apparently I had forgotten to put "set" in there...

    Nevermind.

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    [VBA]
    sub M_snb()
    lastcell=sheets(1).cells(rows.count,3).end(xlup).address
    end sub
    [/VBA]

  4. #4
    Heres another one...

    [vba]
    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
    [/vba]

    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]
    Last edited by Aussiebear; 02-18-2013 at 04:43 PM. Reason: Corrected the tags surrounding the code

  5. #5
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    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....

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,053
    Location
    [QUOTE=magelan]"... 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.


    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.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •