+ Reply to Thread
Results 1 to 3 of 3

Autofill Range Problem

Hybrid View

  1. #1
    Registered User
    Join Date
    02-21-2005
    Posts
    4

    Autofill Range Problem

    I am trying to autofill column A from cell A2 until the last used cell in column B.

    If Column B ends at row 12, fill from A2:A12; if it ends at row 96, fill from A2:A96...however, I cannot seem to figure out how to autofill such a range.

    This is what I have so far:
    -----------------------------------------------------------------------------
    Dim filepath As Variant
    Dim xltmp As Variant
    Dim wb As Variant

    'open the MS Excel worksheet
    Set xltmp = New Excel.Application 'set MS Excel instance
    filepath = txtFileName 'path of the file to be opened
    xltmp.Visible = True 'open MS Excel
    SetAttr filepath, vbNormal 'using this path
    Set wb = xltmp.Workbooks.Open(filepath) 'open the workbook


    'select column A, shift to right, insert column header, fill _
    range with EmpID save workbook, close MS Excel.
    xltmp.Columns("A:A").Select
    xltmp.Selection.Insert Shift:=xlToRight
    xltmp.Range("A1").Select
    xltmp.ActiveCell.FormulaR1C1 = "EmpID"
    xltmp.Range("A2").Select
    xltmp.ActiveCell.FormulaR1C1 = txtEmpID.Value
    xltmp.Selection.AutoFill Destination:=Range("A2:A3"), Type:=xlFillDefault
    'xltmp.Range("A2:A3").Select
    xltmp.ActiveWorkbook.Save
    xltmp.ActiveWorkbook.Close
    xltmp.Quit

  2. #2
    Registered User
    Join Date
    02-21-2005
    Posts
    4

    Autofill Range Problem

    posted this during the holiday and i guess noone saw it **bump**

  3. #3
    Registered User
    Join Date
    02-21-2005
    Posts
    4

    Autofill Range Problem

    Figured it out:


    xltmp.Selection.AutoFill Destination:=Range("A2",Range("B2").End(xlDown),Offset(0,-1)), Type:=xlFillDefault



    or


    Dim xltmp As Excel.Application
    Dim wb As Excel.Workbook

    Set xltmp = New Excel.Application
    filepath = txtFileName
    xltmp.Visible = True
    SetAttr filepath, vbNormal
    Set wb = xltmp.Workbooks.Open(filepath)

    'select column A, shift to right, insert column header, fill _
    range with EmpID save workbook, close MS Excel.
    With wb.Sheets(1)
    .Columns("A:A").Insert
    .Range("A1") = "EmpID"
    .Range("A2:A" & .[b65536].End(3).Row) = txtEmpID.Value
    End With
    wb.Close SaveChanges:=True
    xltmp.Quit
    Set wb = Nothing
    Set xltmp = Nothing

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1