将语句应用于使用VBA的单元格范围 [英] Applying if statement to range of cells using VBA
本文介绍了将语句应用于使用VBA的单元格范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Sub Cleanup()
Dim Segment As String
Dim i As Integer
Segment = ActiveCell(6,3).Value
For i = 6 To 10
If Right(左(段,6),1)=/然后
ActiveCell(i,3).Value = Left(Segment,5)
Else
ActiveCell(i,3).Value = Left(Segment,6)
End If
Next i
End Sub
解决方案
Sub Cleanup()
Dim Segment As String
Dim i As Integer
段=单元格(i,3).Value
对于i = 7到10
如果右(左(段,6),1)=/然后
个单元格(i,3).Value = Left(Segment,5)
Else
单元格(i,3).Value = Left(Segment,6)
End If
Next i
End Sub
I have a small range of cells, C6:C10. I'm trying to apply an if statement to this range of cells using VBA code. Currently, my code takes the output of the if statement for the first cell (C6), and replicates that value for cells C7:C10. The if statement is correct, I'm just not sure how to apply it to a range of cells in a column.
Sub Cleanup()
Dim Segment As String
Dim i As Integer
Segment = ActiveCell(6, 3).Value
For i = 6 To 10
If Right(Left(Segment, 6), 1) = "/" Then
ActiveCell(i, 3).Value = Left(Segment, 5)
Else
ActiveCell(i, 3).Value = Left(Segment, 6)
End If
Next i
End Sub
解决方案
Sub Cleanup()
Dim Segment As String
Dim i As Integer
Segment = Cells(i, 3).Value
For i = 7 To 10
If Right(Left(Segment, 6), 1) = "/" Then
cells(i, 3).Value = Left(Segment, 5)
Else
Cells(i, 3).Value = Left(Segment, 6)
End If
Next i
End Sub
这篇关于将语句应用于使用VBA的单元格范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文