重新编辑到 return 对应的行和列
Refedit to return corresponding row and column
有人可以帮助我在通过 Refedit select编辑范围时检索相应的行和列吗?我把照片放在下面了。
我想做的是当我通过我的用户表单中的 "Refedit1" select 一个范围(例如 E12:E16)时,它应该 return 开始和相应行的结束时间 (11AM - 3PM +1) 和列中的相应日期 (wednesday 26/02/2020)
下一步是将这些值立即插入 3 个 DTPickers 中,但我认为一旦我有了 return 值,我就可以这样做。
我尝试了我发现的所有不同代码,它们总是给我单元格中的值(本例中为“”),文本字符串,如“sheet1$E$12 或当我使用 Active.Cell 它 return 在我通过 RefEdit select 编辑我的范围之前处于活动状态的单元格。
希望有人能指出我正确的方向,我会帮助我很多!抱歉,我无法上传原始 excel 文件,但其中有很多机密信息...
sheet布局
用户表单布局
Private Sub CommandButton2_Click()
Dim rRange As Range
Dim strAddr As String
Dim bIsRange As Boolean
'Get the address, or reference, from the RefEdit control.
strAddr = RefEdit1.Value
'Use IsObject to find out if the string is a valid address.
On Error Resume Next
bIsRange = IsObject(Range(strAddr))
On Error GoTo 0
If bIsRange = False Then 'Not Valid
MsgBox "The range is not valid"
RefEdit1.Value = vbNullString
RefEdit1.SetFocus
Exit Sub
End If
'Set the rRange Range variable to the range nominated by the
'RefEdit control. If the Sheet name is also include (eg Sheet2!A1:A10)
'It will act on that range, even if the sheet is not active at the time.
Set rRange = Range(strAddr)
' gives the cell reference as a string
MsgBox strAddr
With rRange
'.Interior.ColorIndex = 16
.Font.Bold = True
'.BorderAround LineStyle:=xlContinuous, Weight:=xlThick
End With
If strAddr = "" Then
'do nothing
Else
Range(strAddr).Value = UserForm1.ComboBox2.Value
End If
End Sub
您可以这样阅读日期和时间:
With rRange
'.Interior.ColorIndex = 16
.Font.Bold = True
'.BorderAround LineStyle:=xlContinuous, Weight:=xlThick
startTime = .cells(1).EntireRow.cells(2).Value
endTime = .cells(.cells.count).EntireRow.cells(2).Value
theDate = .cells(1).EntireColumn.cells(5).Value
End With
有人可以帮助我在通过 Refedit select编辑范围时检索相应的行和列吗?我把照片放在下面了。
我想做的是当我通过我的用户表单中的 "Refedit1" select 一个范围(例如 E12:E16)时,它应该 return 开始和相应行的结束时间 (11AM - 3PM +1) 和列中的相应日期 (wednesday 26/02/2020) 下一步是将这些值立即插入 3 个 DTPickers 中,但我认为一旦我有了 return 值,我就可以这样做。
我尝试了我发现的所有不同代码,它们总是给我单元格中的值(本例中为“”),文本字符串,如“sheet1$E$12 或当我使用 Active.Cell 它 return 在我通过 RefEdit select 编辑我的范围之前处于活动状态的单元格。
希望有人能指出我正确的方向,我会帮助我很多!抱歉,我无法上传原始 excel 文件,但其中有很多机密信息...
sheet布局
用户表单布局
Private Sub CommandButton2_Click()
Dim rRange As Range
Dim strAddr As String
Dim bIsRange As Boolean
'Get the address, or reference, from the RefEdit control.
strAddr = RefEdit1.Value
'Use IsObject to find out if the string is a valid address.
On Error Resume Next
bIsRange = IsObject(Range(strAddr))
On Error GoTo 0
If bIsRange = False Then 'Not Valid
MsgBox "The range is not valid"
RefEdit1.Value = vbNullString
RefEdit1.SetFocus
Exit Sub
End If
'Set the rRange Range variable to the range nominated by the
'RefEdit control. If the Sheet name is also include (eg Sheet2!A1:A10)
'It will act on that range, even if the sheet is not active at the time.
Set rRange = Range(strAddr)
' gives the cell reference as a string
MsgBox strAddr
With rRange
'.Interior.ColorIndex = 16
.Font.Bold = True
'.BorderAround LineStyle:=xlContinuous, Weight:=xlThick
End With
If strAddr = "" Then
'do nothing
Else
Range(strAddr).Value = UserForm1.ComboBox2.Value
End If
End Sub
您可以这样阅读日期和时间:
With rRange
'.Interior.ColorIndex = 16
.Font.Bold = True
'.BorderAround LineStyle:=xlContinuous, Weight:=xlThick
startTime = .cells(1).EntireRow.cells(2).Value
endTime = .cells(.cells.count).EntireRow.cells(2).Value
theDate = .cells(1).EntireColumn.cells(5).Value
End With