Home > Net >  Loop and list Issue
Loop and list Issue

Time:10-27

I have a problem with loop in VBA macro. I want to loop by a rang in column and set there a list from another column, column to column in same row.

My macro loop by one column but I stuck how to make row to row in that loop.

Eg. in cell O3 macro make a list from data in column D3.

Here is my macro:

Sub List()

Dim range As Range
Dim cell As Range


Set range = Range("O3:O999")


For Each cell In range


Dim list As String
list = Replace(Range("D3").Value, ";", ",")
With cell.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:=list
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
End With

Next cell

End Sub

I try to do another loop in "Replace(Range..." but that was bad idea :D

Any sugestions or problem solving?

Thank you in advance for any help. I'm new to VBA.

CodePudding user response:

Instead of

list = Replace(Range("D3").Value, ";", ",")

you can use:

list = Replace(cell.EntireRow.Columns("D").Value, ";", ",")
  • Related