热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

根据前四列确定空行-Determineemptyrowbasedonfirstfourcolumns

IamusingaUserForminExceltomovecontentfromtextbox1tofirstemptyrowonsheet2.Belowc

I am using a UserForm in Excel to move content from textbox 1 to first empty row on sheet 2. Below command works fine but I would like to consider an empty row only if the first three columns are empty, not all columns (the others columns have some information).

我在Excel中使用UserForm将内容从文本框1移动到工作表2上的第一个空行。下面的命令工作正常,但我想只考虑前三列是空的,而不是所有列(其他列)的空行有一些信息)。

How can I adjust it?

我该怎么调整呢?

Private Sub CommandButton1_Click()
Dim emptyRow As Long

'Make Sheet2 active
With Sheets("Sheet2")

    'Determine emptyRow
    emptyRow = WorksheetFunction.CountA(.Range("A:A")) + 1

    'Transfer information

    .Cells(emptyRow, 1).Value = TextBox1.Value

5 个解决方案

#1


1  

try this:

Private Sub CommandButton1_Click()
    Dim x&, i&, emptyRow&
    emptyRow = 0
    With Sheets("Sheet2")
        For x = 1 To 3
            i = .Cells(Rows.Count, x).End(xlUp).Row
            If emptyRow 

test:

enter image description here

#2


2  

Look from the bottom up.

从下往上看。

emptyRow = application.max(.cells(rows.count, "A").end(xlup).row, _ 
                           .cells(rows.count, "B").end(xlup).row, _
                           .cells(rows.count, "C").end(xlup).row) + 1

#3


0  

Private Sub CommandButton1_Click()
Dim emptyRow As Long, x as Long

'Make Sheet2 active
With Sheets("Sheet2")

    'Determine emptyRow
    x = 0

    Do 

         x = x +1

         emptyRow = WorksheetFunction.CountA(.Range("A" & x & ":C" & x))

    Loop Until emptyRow = 0

    'Transfer information
    .Cells(x, 1).Value = TextBox1.Value

#4


0  

Test the value of those columns for each row until you find the blank one.

测试每行的这些列的值,直到找到空白列。

You can probably do it with a find also but i'm not sure how off the top of my head.

你也可以用一个发现来做,但我不知道我的头脑是多么偏高。

Private Sub CommandButton1_Click()
    Dim ws As Excel.Worksheet
    Set ws = ActiveWorkbook.Sheets("Sheet2")
    Dim emptyRow As Long

    Dim lrow As Long
    lrow = 1

    ws.Activate
    'Loop through the rows
    Do While lrow <= ws.UsedRange.Rows.count

        'Test for an empty row
        If ws.Range("A" & lrow).Value = "" And ws.Range("B" & lrow).Value = "" And ws.Range("C" & lrow).Value = "" Then
            emptyRow = lrow
            Exit Do
        End If

    lrow = lrow + 1
    Loop

    ws.Range("A" & emptyRow).Value = TextBox1.Value

End Sub

#5


0  

Try this:

Private Sub CommandButton1_Click()
Dim emptyRow As Long
Dim row1  As Long, row2 As Long, row3 As Long

'Make Sheet2 active
With Sheets("Sheet2")

'Determine emptyRow
row1 = .Cells(.Rows.Count,1).End(XlUp).Row + 1
row2 = .Cells(.Rows.Count,2).End(XlUp).Row + 1
row3 = .Cells(.Rows.Count,3).End(XlUp).Row + 1

If row1 = row2 And row1 = row3 Then

emptyRow = WorksheetFunction.CountA(.Range("A:A")) + 1

Else

    If row1 >= row2 And row1 >= row3 Then

    emptyRow = row1

    Elseife row2 >= row3 Then

    emptyRow = row2

    Else

    emptyRow = row3

    End If

End If

'Transfer information

.Cells(emptyRow, 1).Value = TextBox1.Value

So what this does, is that it will check if the last row in column A, B and C are the same, and if not, the emptyRow is set on the "largest" last row of columns A, B or C. I hope, that this is what you where looking for. Else ignore this post.

那么它的作用是,它将检查A,B和C列中的最后一行是否相同,如果不是,则在A,B或C列的“最大”最后一行设置emptyRow。我希望,这就是你在寻找的地方。否则忽略这篇文章。


推荐阅读
  • 尽管使用TensorFlow和PyTorch等成熟框架可以显著降低实现递归神经网络(RNN)的门槛,但对于初学者来说,理解其底层原理至关重要。本文将引导您使用NumPy从头构建一个用于自然语言处理(NLP)的RNN模型。 ... [详细]
  • 本文详细介绍了如何使用 Yii2 的 GridView 组件在列表页面实现数据的直接编辑功能。通过具体的代码示例和步骤,帮助开发者快速掌握这一实用技巧。 ... [详细]
  • 基因组浏览器中的Wig格式解析
    本文详细介绍了Wiggle(Wig)格式及其在基因组浏览器中的应用,涵盖variableStep和fixedStep两种主要格式的特点、适用场景及具体使用方法。同时,还提供了关于数据值和自定义参数的补充信息。 ... [详细]
  • 基于KVM的SRIOV直通配置及性能测试
    SRIOV介绍、VF直通配置,以及包转发率性能测试小慢哥的原创文章,欢迎转载目录?1.SRIOV介绍?2.环境说明?3.开启SRIOV?4.生成VF?5.VF ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • 1.如何在运行状态查看源代码?查看函数的源代码,我们通常会使用IDE来完成。比如在PyCharm中,你可以Ctrl+鼠标点击进入函数的源代码。那如果没有IDE呢?当我们想使用一个函 ... [详细]
  • 本文详细介绍了Akka中的BackoffSupervisor机制,探讨其在处理持久化失败和Actor重启时的应用。通过具体示例,展示了如何配置和使用BackoffSupervisor以实现更细粒度的异常处理。 ... [详细]
  • 本章将深入探讨移动 UI 设计的核心原则,帮助开发者构建简洁、高效且用户友好的界面。通过学习设计规则和用户体验优化技巧,您将能够创建出既美观又实用的移动应用。 ... [详细]
  • 获取计算机硬盘序列号的方法与实现
    本文介绍了如何通过编程方法获取计算机硬盘的唯一标识符(序列号),并提供了详细的代码示例和解释。此外,还涵盖了如何使用这些信息进行身份验证或注册保护。 ... [详细]
  • 在过去两周中,我们利用 ReportViewer 开发了与生产良率相关的报表,其中每个制程的直通率是所有测试项良率的乘积。由于 ReportViewer 没有内置的累乘函数,因此需要借助自定义代码来实现这一功能。本文将详细介绍实现步骤和相关代码。 ... [详细]
  • dotnet 通过 Elmish.WPF 使用 F# 编写 WPF 应用
    本文来安利大家一个有趣而且强大的库,通过F#和C#混合编程编写WPF应用,可以在WPF中使用到F#强大的数据处理能力在GitHub上完全开源Elmis ... [详细]
  • DNN Community 和 Professional 版本的主要差异
    本文详细解析了 DotNetNuke (DNN) 的两种主要版本:Community 和 Professional。通过对比两者的功能和附加组件,帮助用户选择最适合其需求的版本。 ... [详细]
  • 如何高效创建和使用字体图标
    在Web和移动开发中,为什么选择字体图标?主要原因是其卓越的性能,可以显著减少HTTP请求并优化页面加载速度。本文详细介绍了从设计到应用的字体图标制作流程,并提供了专业建议。 ... [详细]
  • 实体映射最强工具类:MapStruct真香 ... [详细]
author-avatar
手机用户2502921201
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有