excel - 手动输入与通过用户表单和文本框输入之间的区别
问题描述
当我搜索使用用户表单插入的单元格的值时,我的查找功能不起作用,但是当我手动键入值时起作用。
代码应该从单元格中取出值并使用日历中的查找功能对其进行搜索,然后插入一个形状。(就像在甘特图中一样。)
当我手动输入开始日期和结束日期时,没有错误,一切正常。
当我使用我的用户表单输入开始和结束日期时,我收到运行时错误 91。
在单元格中输入值的这两种可能性之间的区别在哪里?
我的用户表单:
Private Sub Create_Click()
'Einträge Übernehmen
Worksheets("Muster").Range("A1").Value = newProject.ProjectName.Value
Worksheets("Muster").Range("D1").Value = newProject.StartDate.Value
Worksheets("Muster").Range("F1").Value = newProject.EndDate.Value
Worksheets("Muster").Range("C1").Value = newProject.CustumerName.Value
'Project aus Muster Kopieren und in Projectplan einfügen
Worksheets("Muster").Range("A1:F16").Copy
Worksheets(1).Range("A1048576").End(xlUp).Offset(2, 0).PasteSpecial
'Maske nach Knopfdruck schließen
Unload newProject
'alte einträge Löschen
Worksheets(2).Range("D1:D16").ClearContents
Worksheets(2).Range("F1:F16").ClearContents
End Sub
我的子程序插入酒吧:
Sub RangeToShape(myRange As Range, Color As Integer)
'Erzeugt ein Shape Objekt nach vorbild einer Range
Dim posLeft As Long
Dim posTop As Long
Dim posWidth As Long
Dim posHeight As Long
Dim myShape As Shape
posLeft = myRange.Left
posTop = myRange.Top
posWidth = myRange.Width
posHeight = myRange.Height
With myRange.Parent
Set myShape = .Shapes.AddShape(msoShapeRectangle, posLeft, posTop, posWidth, posHeight)
If Color = 1 Then
myShape.Fill.ForeColor.RGB = XlRgbColor.rgbDarkGray
ElseIf Color = 2 Then
myShape.Fill.ForeColor.RGB = ColorConstants.vbGreen
ElseIf Color = 3 Then
myShape.Fill.ForeColor.RGB = ColorConstants.vbYellow
End If
End With
End Sub
Sub refresh()
'Refresh button
Dim i As Integer
Dim findStart As Range
Dim findEnd As Range
ShapesLoeschen
For i = 5 To CInt(Worksheets(1).Range("D1048576").End(xlUp).Row)
If Not IsEmpty(Cells(i, 4).Value) And Not IsEmpty(Cells(i, 6).Value) Then
Set findStart = Tabelle1.Rows("2").Find(What:=Cells(i, 4).Value, LookIn:=xlFormulas)
Set findEnd = Tabelle1.Rows("2").Find(What:=Cells(i, 6).Value, LookIn:=xlFormulas)
'Error Report: programmierte Zellen haben innerhalb kein Datum, sondern anscheind nur einen Verweis oder so
'Error Report: In die Felder können Dati eingetragen werden die am Wochenende sind, ergo die nicht in der Liste sind _
Quick fix: Wochenenden mit aufnehmen
If Cells(i, 2).Value = 1 Then
RangeToShape Range(findStart.Offset(i - 2, 0), findEnd.Offset(i - 2, 0)), 1
ElseIf Cells(i, 2).Value = 2 Then
RangeToShape Range(findStart.Offset(i - 2, 0), findEnd.Offset(i - 2, 0)), 2
ElseIf Cells(i, 2).Value = 3 Then
RangeToShape Range(findStart.Offset(i - 2, 0), findEnd.Offset(i - 2, 0)), 3
End If
End If
Next
End Sub
主要问题是如果我通过用户表单输入日期,则子刷新()中的查找功能找不到日期。
解决方案
推荐阅读
- c# - Better way to load fk without navigation property
- python - statsmodel ARIMA dynamic forecasting with exogenous regressor
- docker - docker-machine create command hangs at waiting for an IP
- python - 字典列表:按字典的值排序
- css - 如何使 ng-show/ng-hide 过渡动画更流畅
- r - 如何将数据合并为一个?
- amazon-web-services - Column name with a Space - Athena
- android - 带有 Visual Studio 的 Android 上的 Vulkan
- jquery - 如何将编辑和删除按钮添加到动态创建的列到每一行
- android - 单击文本字段后,底部的约束布局按钮不可见