+ Reply to Thread
Results 1 to 6 of 6

Writing data on last empty cell in a column

  1. #1
    Registered User
    Join Date
    10-07-2015
    Location
    Philippines
    MS-Off Ver
    2010
    Posts
    4

    Writing data on last empty cell in a column

    Hi!
    So.. I select a Phase , which gives me the specific structure codes for that phase, then I input the number of sets that are needed. Finally, I press the command button to record the data in the "Data" sheet . It writes the data on the "Data" worksheet in the first column (pcs) However, if I enter another set of data from the "Steel Pole" Worksheet, it overwrites the previously recorded data. My guess is because I assigned numerical values to the row and column in my vba code. Possible fix would be to find the next empty cell in the column and make the next set of data write from there. Any help would be much appreciated

    Dropbox file for Reference
    https://www.dropbox.com/s/f35c4e07vl...lock.xlsm?dl=0

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Writing data on last empty cell in a column

    Try this amended version of your code (see attached).

    BSB
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    06-02-2015
    Location
    delhi
    MS-Off Ver
    2010
    Posts
    104

    Re: Writing data on last empty cell in a column

    put this code in command button click event

    Private Sub CommandButton1_Click()
    Dim Row As Integer
    If Range("C15").Value = "" Or Range("C17").Value = "" Then
    MsgBox ("Select Structure code and Input Quantity of Materials")
    Else
    Row = 2
    Set ws = ActiveSheet
    lr = Application.WorksheetFunction.Count(Range("E15:E50")) + 14
    Worksheets("Steel Pole").Range("E14:G" & lr).Copy
    lr = Worksheets("data").Cells(Rows.Count, 1).End(xlUp).Row
    Worksheets("Data").Cells(lr + 1, 1).PasteSpecial Paste:=xlPasteValues
    MsgBox ("The data has been recorded!")
    Range("C15", "C17").Value = ""
    Application.CutCopyMode = False
    End If

    End Sub

  4. #4
    Registered User
    Join Date
    10-07-2015
    Location
    Philippines
    MS-Off Ver
    2010
    Posts
    4

    Re: Writing data on last empty cell in a column

    Quote Originally Posted by BadlySpelledBuoy View Post
    Try this amended version of your code (see attached).

    BSB
    All Right! BSB to the rescue. Exactly what I was looking for. Replicating the codes for the other 2 columns was easy enough. Thanks a ton

  5. #5
    Registered User
    Join Date
    10-07-2015
    Location
    Philippines
    MS-Off Ver
    2010
    Posts
    4

    Re: Writing data on last empty cell in a column

    Quote Originally Posted by Mandeep Baluja View Post
    put this code in command button click event

    Private Sub CommandButton1_Click()
    Dim Row As Integer
    If Range("C15").Value = "" Or Range("C17").Value = "" Then
    MsgBox ("Select Structure code and Input Quantity of Materials")
    Else
    Row = 2
    Set ws = ActiveSheet
    lr = Application.WorksheetFunction.Count(Range("E15:E50")) + 14
    Worksheets("Steel Pole").Range("E14:G" & lr).Copy
    lr = Worksheets("data").Cells(Rows.Count, 1).End(xlUp).Row
    Worksheets("Data").Cells(lr + 1, 1).PasteSpecial Paste:=xlPasteValues
    MsgBox ("The data has been recorded!")
    Range("C15", "C17").Value = ""
    Application.CutCopyMode = False
    End If

    End Sub
    Nice! I tried your code out and it worked flawlessly too. Thanks for this

  6. #6
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Writing data on last empty cell in a column

    Glad I could help.

    If you're transferring more than one column over to the data sheet then Mandeep's copy and paste approach makes far more sense.
    I just wanted to show you where your method was going awry.

    Thanks for the rep point

    BSB

+ 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] Writing a Cell data into another column 6 times - Google Spreadsheet
    By cemsultan in forum Excel General
    Replies: 5
    Last Post: 05-11-2016, 05:03 PM
  2. error writing to cell if a numeric text box is empty
    By Roberta.Walker in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-07-2016, 02:34 PM
  3. Copy data and paste to another column incrementing that column to next empty cell
    By edens2021 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-29-2015, 11:43 AM
  4. Writing Data to first empty cell in column A
    By edens2021 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-28-2015, 02:42 PM
  5. [SOLVED] userform data to cell in empty column
    By mabulco in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-07-2013, 07:17 AM
  6. [SOLVED] While writing files from another workbook, keep empty cells empty!
    By nivoe in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-09-2012, 12:25 PM
  7. [SOLVED] How to copy data to the next empty cell in a column
    By suruukko in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-22-2006, 07:40 AM

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