Forum Discussion

LeonelAFM's avatar
LeonelAFM
Copper Contributor
Jul 30, 2022
Solved

Macro VBA Excel - Conditioned copy of reference cell to a range of side cells

First, thanks for the help. I made a test macro for the first time to see if it worked and it was OK. However, it references a single cell due to the test. Now, I need to extend this macro to a ran...
  • HansVogelaar's avatar
    Jul 30, 2022

    LeonelAFM 

    Sub Copiar()
        Dim r As Long
        Dim n As Long
        Application.ScreenUpdating = False
        For r = 104 To 108
            n = Application.RoundUp(Range("S" & r).Value, 0)
            If n <= 0 Then
                n = 1
            ElseIf n > 6 Then
                n = 6
            End If
            Range("T" & r).Resize(1, n).Value = Range("S" & r).Value
        Next r
        Application.ScreenUpdating = True
    End Sub

    Remark: a line such as

    If Range("S104") > 1 <= 2 Then

    is not valid. It should be

    If Range("S104") >1 And Range("S104") <= 2 Then

Resources