output data to next empty cell in a row

cccbzg

Board Regular
Joined
Oct 5, 2014
Messages
68
Office Version
  1. 365
Platform
  1. Windows
Hi,

I want to put the value in DDXit in the next available cell on the active row. As a stop gap for testing, I just hard-coded the column (last two lines), but I'm at the point that I need to get the thing to work.

All help is much appreciated.

Bonnie

With Sheets("DATA ANALYSIS")
Set NextRow = .Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0)
MsgBox NextRow
'find last used cell on the row to the right
ActiveCell.End(xlToRight).Select

'move one cell to the right from the last used cell
ActiveCell.Offset(0, 1).Select
'
End With

Cells(arow, 4) = SErng
Cells(arow, 5) = DDXit

'****************
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi.

I would try something like this:
Code:
Sub FillNextCell()

    Dim NextCell As Range

    With Sheets("DATA ANALYSIS")
        Set NextCell = .Cells.Find("", Range("A1"), , , xlByRows, xlNext)
        NextCell = SErng
        Set NextCell = .Cells.Find("", Range("A1"), , , xlByRows, xlNext)
        NextCell = DDXit
    End With
    
End Sub

The FIND statement locates the next blank cell after cell A1.
I have used FIND twice because it copes with the case when a row becomes full because it automatically moves on to the next row.
 
Upvote 0
Thanks so very much! That helped, but I need the row to be a variable "arow." I had Cells(arow, 5) = DDXit to put DDXit in col 5 of the variable row "arow." I'm not sure where to put that in the code you were kind enough to provide.

Again, my thanks.
Bonnie
 
Upvote 0
Instead of starting the search at cell A1 as I have you will need to pick a cell in the row you want.

You can use Range or Cells to set the first cell.
Something like this, perhaps:
Code:
Sub FillNextCell()

    Dim NextCell As Range
    Dim aRow As Long
    
    SErng = "#####"
    DDXit = "@@@@@"
    
    aRow = 7
    With Sheets("DATA ANALYSIS")
        Set NextCell = .Cells.Find("", .Cells(aRow, 1), , , xlByRows, xlNext)
        NextCell = SErng
        Set NextCell = .Cells.Find("", .Cells(aRow, 1), , , xlByRows, xlNext)
        NextCell = DDXit
    End With
    
End Sub

Instead of .Cells(aRow, 1) you could use .Range("A" & aRow).
In fact, you can use any range object that defines a suitable starting point.
 
Upvote 0

Forum statistics

Threads
1,215,770
Messages
6,126,791
Members
449,336
Latest member
p17tootie

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top