VBA Multi-column list box from sheet columns - excel

I've got a spreadsheet with two sheets, lets call them Sheet A and Sheet B.
From Sheet A, I click a button and it opens a form with a listbox.
Sheet B has 10 columns of data.
I want to select 3 of these columns contents, (A, B, F).
And display them in this one listbox in different columns but it just isn't working and can't find the correct way to do this..
This is what I have so far:
git://gist.github.com/4131461.git
So in the end I want a list box with 3 columns, each populate with the ranges 1-10 from 3 columns..
I just started doing VBA and I have no idea how to do this..
Help?

lbData is the listbox, change Sheet2 as appropriate to reference your data. Add the below in the userform:
Private Sub UserForm_Initialize()
With Me.lbData
.ColumnCount = 3
.ColumnWidths = "33;33;33"
.RowSource = Sheet2.Range("A1:C10").Address
End With
End Sub

Related

How to setup a Excel Button to execute two specifc VBA Macros?

Can someone help me with the following queries.
I have an Excel file with four sheets - Sheet A, Sheet B, Sheet C, Sheet D
In Sheet A - contain all Formulas and Calculations.
Sheet D has the Excel VBA Button with the following Macro is created and it is being filling correctly data in Sheet B
Sub CopySelectedColumnToNxSh()
"CopySelectedColumnToNxSh Macro"
Sheets("A").Range("E1:E14").Copy
Sheets("B").Range("A530").End(xlUp).Offset(1, 0).Range("A1").PasteSpecial xlPasteValues, Transpose:=True
End Sub
I would like to add another function to the button that can executes the following
Copy values from Sheet A to Sheet C where there is a table with Header (Months - Jan to Feb) and occupied first Column A. I would like to copy the values under each Month Column from this range B2:M11 without overwriting the previous one
I am trying with the following code but I'm not able to set it to move to new column
Sub Year_1()
Sheets("A").Range("E1:E10").Copy Destination:=Sheets("C").Range("B2")
End Sub
Can a logic be added for the button that for each 12 Clicks (Sheet C copy range is filled) it creates another sheet in the table.

VBA Range_Copy Macro - How to apply same task to subsequent rows

I have a working spreadsheet with lists of items. One field could have 1 of 14 descriptions. I thought creating a macro would be quicker than manually going to a separate sheet and copying and pasting the desired description every time.
I am totally new to this, but was able to create a macro grabbing data in cell A1 in one sheet and adding that data to cell S3 in another sheet - see code below. (Each description has its own sheet with data in cell A1) My question is, how to move onto the next row and cell S4. Thanks in advance!
Sub Range_Copy()
Worksheets("Used Single Items Returns").Range("A1").Copy Worksheets("Gopher Items CSV Test").Range("S3")
End Sub
If you just want to copy into Col S on the selected row:
Sub Range_Copy()
Dim r
Set r = Selection.Cells(1).entirerow.range("S1") 'relative to row, not sheet
Worksheets("Used Single Items Returns").Range("A1").Copy r
End Sub

Vba combobox using non-active sheet

I have a combobox to a userform and the its not an activesheet in excel so not sure how to go about it.
The sheet name is "DoNotPrint - Rate Index" and the values within that sheet to appear in the combobox are the columns C2:AS2.
Private Sub ComboBox1_Change()
Sheets("DoNotPrint - Rate Index").Range("C2:AS2") = ComboBox1.Value
End Sub
I tried this code and the combobox list isn't populating those column when the combobox list button is clicked.
The code you posted is for taking what's in the combobox and putting it on the sheet, when it's selected. But if I understand correctly your issue is you can't get the combobox populated. Because you are using a single row as your dataset and not a single column you will need to transpose your data.
Private Sub UserForm_Initialize()
ComboBox1.List = WorksheetFunction.Transpose(Sheet1.Range("C2:AS2"))
End Sub

How do you change a cell based on a combobox value

I have a sheet (sheet A) with an activeX combobox, this combobox is filled with dates from another sheet (sheet B) on the format "dd/mm/yyyy" in text.
Now what i want is that when i select some date in the combobox on sheet A, i get the same date in another cell but 2 years add to it. So if i select "01/01/2018" i get "01/01/2020". Any help?
Use
Option Explicit
Private Sub ComboBox1_Change()
Range("A2") = DateAdd("yyyy", 2, Me.ComboBox1.Value)
End Sub
Code goes in code pane of sheet containing the activex object. Change A2 to the target output cell and ComboBox1 to the appropriate combobox.

Reading and Displaying lists value trough VBA code

Please somebody help me in reading values from excel drop down list and copmare these values with the values in the different cells and display results in VBA excel
I have 3 drop down list and i will compare these values with the values in other cells, if it matches i will display the values for that.
I have 2 sheets , Sheet1 and Sheet2. in Sheet1 i have 3 dropdown lists, where i will select the values. When i select these values, i need to search these values in the table exists in the sheet2. And the values to be displayed in a perticular cell. How to do it. Please help
do you maybe look for something like that?
Private Sub ComboBox1_Change()
If ComboBox1.Value = Range("E3").Text Then
MsgBox "Same Values"
End If
End Sub

Resources