简体   繁体   English

将数据传输到VBA中后,在动态范围内查找和替换空白单元格

[英]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? 我意识到我实际上是在告诉excel用句点填充A到J列,所以我的问题是,是否有一种更简单的方法可以执行此操作,或者可以指定我只需要最近的行来包含句点?

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.,,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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