当系统时间和Range("a" & i)相同时,显示Range("b" & i)内容
vba吧
全部回复
仅看楼主
level 1
marm0t 楼主
代码如下:
Sub 显示成交()
Dim t As Date
Dim txtBox As Shape
Dim txtbox1 As Shape
Do
t = Time ' 获取时间
' 添加文本框
Set txtBox = ActiveSheet.Shapes.AddTextbox( _
msoTextOrientationHorizontal, _
Left:=1, Top:=1, Width:=370, Height:=170)
' 设置文本框的字体大小
txtBox.TextFrame2.TextRange.Font.Size = 48
' 设置文本框背景颜色
txtBox.Fill.ForeColor.RGB = RGB(255, 255, 160)
txtBox.Fill.Visible = msoTrue
' 设置文本框字体加粗
txtBox.TextFrame2.TextRange.Font.Bold = msoTrue
For i = 1 To Range("A1").End(xlDown).Row
If Range("a" & i).Text = Format(t, "hh:mm:ss") Then txtBox.TextFrame2.TextRange.Text = Range("b" & i)
Next
DoEvents
Loop
End Sub
测试程序的时候,总是跳过a列中某些时间,不显示对应b列内容,这是什么问题?
传不了excel文件,我截图。
测试结果我传个视频,截取了一小段。
352.353.断.355.356.断.367.368.369.断.372.373.断.375
2024年08月04日 09点08分 1
level 7
我也是VBA初学者。
这种情况,告诉你知道办法。
问AI即可(免费的百度文心一言即可),给你解释的清清楚楚明明白白,还给你代码。。。
2024年08月04日 10点08分 2
还给你修改正确代码
2024年08月04日 10点08分
level 5
你A列的时间不是连续的,获取的时间点对不上。
2024年08月04日 14点08分 3
level 1
Set txtBox = ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, Left:=1, Top:=1, Width:=370, Height:=170)
' 设置文本框的字体大小
txtBox.TextFrame2.TextRange.Font.Size = 48
' 设置文本框背景颜色
txtBox.Fill.ForeColor.RGB = RGB(255, 255, 160)
txtBox.Fill.Visible = msoTrue
' 设置文本框字体加粗
txtBox.TextFrame2.TextRange.Font.Bold = msoTrue
上面这堆放到DO外面,设置一次就可以
For i = 1 To Range("A1").End(xlDown).Row
If Range("a" & i).Text = Format(t, "hh:mm:ss") Then txtBox.TextFrame2.TextRange.Text = Range("b" & i)
Next
上面这段不要,增加下面的内容
dim RngA as range
dim Ws as worksheet
dim TextTmp
set ws = activesheet
在Do里面增加以下内容
set rnga = ws.range("A:A").find(Format(t, "hh:mm:ss"),LookIn:=xlValues, LOOKAT:=xlWhole)
if not rnga is nothing then
TextTmp = txtBox.TextFrame2.TextRange.Text
if TextTmp <> "" then TextTmp = TextTmp & vbCr
txtBox.TextFrame2.TextRange.Text = TextTmp & Range("b" & rnga.row).text
end if
唯一的问题是你这个DO没有跳出条件,这个是要不停的取数据的?
2024年08月05日 01点08分 6
1