简体   繁体   English

查找最后一行,选择行中的特定列

[英]Find last row, select specific column in row

I'm just starting to learn VBA and I've tried to find solutions here but to no avail. 我才刚刚开始学习VBA,并且试图在这里找到解决方案,但无济于事。 I'm seeking a VBA macro for this: 我正在为此寻找VBA宏:

I have a sheet in my workbook called LOG that gets a timestamp in column A when I start to fill the row. 我的工作簿中有一个名为LOG的工作表,当我开始填写该行时,它会在A列中获得一个时间戳。 Once I've completed a task I use =CONCATENATE in column I to summarize the rows A through H. Column I has the formula content filled down to row 300 or more. 完成任务后,我在第I列中使用=CONCATENATE来汇总A至H行。第I列的公式内容填充到第300行或更多。 Column A is blank until I enter a time-stamp ( "ctrl + :" ). 在输入时间戳记(“ ctrl +:”)之前,列A为空白。

What I am seeking to do is run a macro through a command button where it will find the last timestamped row in column A, and then select and copy contents (not the formula) of that row in column I to clipboard. 我要执行的操作是通过命令按钮运行宏,它将在A列中找到带有时间戳的最后一行,然后选择并将I列中该行的内容(而不是公式)复制到剪贴板。

I've tried to modify so many different suggestions I've found in stackoverflow but with little success. 我试图修改在stackoverflow中发现的许多不同建议,但收效甚微。 I'm not sure really what I'm doing wrong and I've tried so many of them I don't know which I would share with you for an example. 我不确定自己在做什么错,我尝试了很多尝试,但我不知道我会与您分享哪个示例。 Any help would be very appreciated! 任何帮助将不胜感激! Thanks again! 再次感谢!

1) Define a function to copy some text to the clipboard: 1)定义一个将一些文本复制到剪贴板的函数:

Sub CopyText(Text As String)
    'VBA Macro using late binding to copy text to clipboard.
    'By Justin Kay, 8/15/2014
    Dim MSForms_DataObject As Object
    Set MSForms_DataObject = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
    MSForms_DataObject.SetText Text
    MSForms_DataObject.PutInClipboard
    Set MSForms_DataObject = Nothing
End Sub

Then something like this: 然后是这样的:

Sub GetLastTimestampAndCopy()
    dim ws as worksheet
    dim strValue as string
    dim lngLastRow as long

    set ws = Activeworkbook.Worksheets("LOG")

    ' Get the last populated cell in the first column
    lngLastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row

    ' Get corresponding value in the same row but in column I
    strValue = ws.Cells(lngLastRow, 9).Value

    CopyText strValue
End Sub

Execute the second SUB and you should have the value on your clipboard. 执行第二个SUB,您应该在剪贴板上具有该值。

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

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