简体   繁体   中英

Find & Replace blank cells in a dynamic range after transfering data into it VBA

Okay I know there are multiple questions similar to this, but at least from what I've found, my problem is different so please bear with me. I am building a user form that allows users to input data into a tracking sheet, but there are certain scenarios where only part of the data will get submitted at a time,leaving "holes" in the tracking sheet. My goal is to fill these "holes" with a period so that way relevant data will stay together in the same row instead of getting bumped up into those holes.

Sheets("Tracker").Activate
Worksheets("Tracker").Columns("A:J").Replace What:="", Replacement:=".", _
    SearchOrder:=xlByColumns, MatchCase:=False

I realize I am essentially telling excel to fill columns A through J with a period, so my question is, is there an easier way to do this, or a way to specify that I only need the most recent row to contain the periods?

Update: This is the code I am using to find the next available row in the tracker for new data to go. Thus when portions of the previous row are missing, the macro fills those unused cells with the next rows data.

Set ws = Sheets("Tracker") Sheets("Tracker").Select 
ws.Range("E" & LastRow).Value = job_txtb.Text    
'Finds the last blank row
LastRow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row + 1 
'Adds the Job name Code into Col E & Last Blank Row

The following will give you the first unused row. I don't understand why periods would be necessary.

With ActiveSheet
    On Error Resume Next
    lastRow = .Cells.Find("*", .Cells(.Cells.Count), xlFormulas, _
    xlWhole, xlByRows, xlNext).Row
    If Err <> 0 Then lastRow = 0
End With
firstUnusedRow = lastRow + 1

Range("A" & firstUnusedRow).Value = Textbox1.Value
Range("B" & firstUnusedRow).Value = Textbox2.Value
Range("C" & firstUnusedRow).Value = Textbox3.Value
'etc.
'etc.,,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM