+ Reply to Thread
Results 1 to 6 of 6

Enter Row Number as a value in cells

Hybrid View

  1. #1
    Registered User
    Join Date
    04-02-2012
    Location
    Earth
    MS-Off Ver
    Excel 2013
    Posts
    33

    Enter Row Number as a value in cells

    Hi I'm using tables in excel and importing data from different documents. I have got the browse, open, and import (copy paste) nailed down.

    when I import the data into the table it populates all but the first column as this is a unique sequential ID. I has chosen to use the row number.

    So just before import in the vba I sort the table via this ID column and add the new data to the end.

    I then want to add the unique sequential ID number to the new data.

    so far I have.... nothing that works

        Dim lastRow As Long
    
        ' get the last row from column A that has a value
        Dim FirstBlankCell As Range
        Set FirstBlankCell = Workbooks("Temp").Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
    
        lastRow = Worksheets("Sheet1").Range("A" & Worksheets("Sheet1").Rows.Count).End(xlUp).Row
    
        ' use the last row to determine how far down to extend the formula
        'Worksheets("Sheet1").Range("A" & FirstBlankCell).Formula = "=row()"
        'Worksheets("Sheet1").Range("D" & lastRow + 1).Value = Workbooks(Filename).Name
            
    'lrowp = Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
    'Worksheets("Sheet1").Range("A2:A" & lrowp).Copy
    'Worksheets("Sheet1").Range("A2:A" & lrowp) _
    '        .PasteSpecial Paste:=xlPasteValues
    
    MsgBox FirstBlankCell
    any ideas? When I have this working I also want to include the file name in the last column as when opening the file the first check is has it already been imported

    thanks

    additional information - I have the copy paste as values only as when sorting tables with a formula reference row it obviously changes to what ever row it sits in messing up the data
    Last edited by vew32; 09-25-2013 at 10:13 AM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644
    How does the code not work?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    04-02-2012
    Location
    Earth
    MS-Off Ver
    Excel 2013
    Posts
    33

    Re: Enter Row Number as a value in cells

    Hi Norie

    Before I started hacking at the code using bits I learnt here and there, it was adding a single unique code in the first empty cell under the table in column A rather than looking in the table for the first empty cell in column A or table column name ID

  4. #4
    Registered User
    Join Date
    04-02-2012
    Location
    Earth
    MS-Off Ver
    Excel 2013
    Posts
    33

    Re: Enter Row Number as a value in cells

    ok so I have made things work but not exactly how I want it

    I now have the following

    With Worksheets("Sheet1").Range("Table1[Item number]")
    
           Worksheets("Sheet1").Range("Table1[Item number]").SpecialCells _
         (xlCellTypeBlanks).Formula = "=row()-1"
    End With
    this fills the missing data but with a formula. I can copy paste the who column as values only I guess but as the document grows this will take longer and longer.

    is there a better way of getting the value?

    thanks

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Enter Row Number as a value in cells

    If you don't want the formula do a copy and paste special values.
    With Worksheets("Sheet1").Range("Table1[Item number]").SpecialCells _
         (xlCellTypeBlanks)
         .Formula = "=row()-1"
         .Value = .Value
    End With

  6. #6
    Registered User
    Join Date
    04-02-2012
    Location
    Earth
    MS-Off Ver
    Excel 2013
    Posts
    33

    Re: Enter Row Number as a value in cells

    Thanks Norie that is perfect exactly what I wanted

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How do I create a button to enter a number in a cell and then tab/enter to next cell
    By MatiasGarcia in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-21-2013, 05:29 PM
  2. auto enter number macro then search for rest of number
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-22-2013, 04:24 PM
  3. Formula to enter highest number from a range of cells
    By batjl9 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-26-2011, 04:32 PM
  4. Replies: 1
    Last Post: 04-26-2006, 06:10 AM
  5. [SOLVED] How do I quickly enter the same number into different cells?
    By Cheers100 in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 02-18-2006, 10:30 AM

Tags for this Thread

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