Hello,
My question is how to make 2 variables change at the same time with a "for each" statement in VBA. For example, I would like to make the C and D variable change together instead of only one changing. My problem is that every time my code is doing a loop, only the C variable is changing. This is being done on 2 different columns where I want it to go to the next row each time such as
1 2
2 4
5 6
________________
Sub stuff()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
ActiveSheet.Range(Cells(2, 2), Cells(65536, 2).End(xlUp)).Select
Selection.Copy
Range("C2").Select
ActiveSheet.Paste
Set ws = ActiveWorkbook.Sheets("CMRData")
Dim c As Range
Dim d As Range
For Each c In ActiveSheet.Range(Cells(2, 3), Cells(65536, 3).End(xlUp))
For Each d In ActiveSheet.Range(Cells(2, 6), Cells(65536, 6).End(xlUp))
If Not IsNumeric(d.Value) Then
If Len(c.Value) = 6 Then
c.Value = Left(c.Value, 5)
End If
ElseIf Not IsNumeric(d.Value) Then
If Len(c.Value) = 5 Then
c.Value = Left(c.Value, 5)
End If
Else
c.Value = ""
End If
Exit For
Next d
Next c
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
---------------------------
Thanks!
My question is how to make 2 variables change at the same time with a "for each" statement in VBA. For example, I would like to make the C and D variable change together instead of only one changing. My problem is that every time my code is doing a loop, only the C variable is changing. This is being done on 2 different columns where I want it to go to the next row each time such as
1 2
2 4
5 6
________________
Sub stuff()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
ActiveSheet.Range(Cells(2, 2), Cells(65536, 2).End(xlUp)).Select
Selection.Copy
Range("C2").Select
ActiveSheet.Paste
Set ws = ActiveWorkbook.Sheets("CMRData")
Dim c As Range
Dim d As Range
For Each c In ActiveSheet.Range(Cells(2, 3), Cells(65536, 3).End(xlUp))
For Each d In ActiveSheet.Range(Cells(2, 6), Cells(65536, 6).End(xlUp))
If Not IsNumeric(d.Value) Then
If Len(c.Value) = 6 Then
c.Value = Left(c.Value, 5)
End If
ElseIf Not IsNumeric(d.Value) Then
If Len(c.Value) = 5 Then
c.Value = Left(c.Value, 5)
End If
Else
c.Value = ""
End If
Exit For
Next d
Next c
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
---------------------------
Thanks!