• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Column headings in a combobox!

praveenkrishnag

New Member
I would like to know how you can incorporate a combobox with column headings in a combobox so that when a column is selected from the list, the data entered into the corresponding column appears in the data sheet.
 
Try this where the combo box refers to F1 on sheet1 and the data "to appear" is in columns A, B, C, D of sheet2.


Regards,

Howard

[pre]
Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim colA As Long
Dim colB As Long
Dim colC As Long
Dim colD As Long
Dim ColDa As Variant

If Target.Address <> "$F$1" Then Exit Sub

Range("A:A").ClearContents

Select Case Target.Value

Case Is = "colA"
colA = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row
Sheets("Sheet2").Range("A1:A" & colA).Copy Sheets("Sheet1").Range("A100").End(xlUp).Offset(1, 0)

Case Is = "colB"
colA = Sheets("Sheet2").Range("B" & Rows.Count).End(xlUp).Row
Sheets("Sheet2").Range("B1:B" & colA).Copy Sheets("Sheet1").Range("A100").End(xlUp).Offset(1, 0)

Case Is = "colC"
colA = Sheets("Sheet2").Range("C" & Rows.Count).End(xlUp).Row
Sheets("Sheet2").Range("C1:C" & colA).Copy Sheets("Sheet1").Range("A100").End(xlUp).Offset(1, 0)

Case Is = "colD"
colA = Sheets("Sheet2").Range("D" & Rows.Count).End(xlUp).Row
Sheets("Sheet2").Range("D1:D" & colA).Copy Sheets("Sheet1").Range("A100").End(xlUp).Offset(1, 0)

End Select
End Sub
[/pre]
 
Back
Top