Eduards
Eduards

Reputation: 68

VBA Excel ComboBox value to Range ("specific cell" to last column with data)

I am trying to fill a range of cells from a single ComboBox and I am not sure why my modified code of declaring range from cell down to last used row doesn't work when I flip it horizontally and declare range from cell to last used column on the right of the specified cell which is "C1"

    Dim LastColumn As Long
    LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column

Worksheets("Machine Format").Range("C2" & LastColumn).Value = UserForm_Home.Language_ComboBox.Text

I am judging if it's the last used column by it's header row which won't be blank.

Could someone, please, help me with this code?

Upvotes: 0

Views: 528

Answers (1)

BigBen
BigBen

Reputation: 50008

Since you're working with the column index, use Cells instead of Range.

With Worksheets("Machine Format")
    .Range("C2", .Cells(2, LastColumn)).Value = UserForm_Home.Language_ComboBox.Text
End WIth

Use With Worksheets("Machine Format") and a period . before Cells to properly qualify the worksheet for the Cells call.

Upvotes: 1

Related Questions