Userform to worksheet code advice

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
2,823
Morning,

I have a simple userform which i will select a Month & Year from the drop down box & when i press the command button it will place the selected values into there respective cells.

I wish the userform to appear when i open the worksheet BUT only if the cell in question is empty.
Should there be a value in the cell then dont open the userform.

Many thanks.
Here is the info.

Cell for where the code should look to see if the userform needs to be shown etc is worksheet INCOME (1) cell B1

Userform Info
ComboBox1 value should be sent to cell INCOME (1) cell B1

ComboBox2 value should be sent to cell INCOME (1) cell B2

CommandButton1 is pressed to send values from userform to Worksheet

Have a weekend.
 

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
2,823
Hi,
Im trying to edit another code to use on this worksheet.
The code i have is shown below.

I select the from the two drop down options & press the TransferButton.
I see a new row inserted & the Month is entered in cell A3 & the year is entered in the cell B3

What im stuck with on this is the following.

Dont insert a new row.
Enter month in cell B1 NOT cell A3
Enter Year in cell B2 NOT cell B3

I think it has something to do with the red text below but im not sure i understand it so i cant fix it.

Thanks


Code:
Private Sub TransferButton_Click()    Dim i As Integer
    Dim ControlsArr As Variant, ctrl As Variant
    Dim x As Long
    For i = 1 To 2
       With Me.Controls("ComboBox" & i)
            If .ListIndex = -1 Then
                MsgBox "MUST SELECT BOTH OPTIONS", 48, "MONTH & YEAR TRANSFER MESSAGE"
                .SetFocus
                Exit Sub
            End If
        End With
    Next i
    
    ControlsArr = Array(Me.ComboBox1, Me.ComboBox2)
    
    With ThisWorkbook.Worksheets("INCOME (1)")
[COLOR=#ff0000]        .Range("B1").EntireRow.Insert Shift:=xlDown
        For i = 0 To UBound(ControlsArr)
         Select Case i
            Case 1, 2, 4
               .Cells(4, i + 1) = IIf(IsNumeric(ControlsArr(i)), Val(ControlsArr(i)), ControlsArr(i))
            Case Else
               .Cells(4, i + 1) = ControlsArr(i)
               ControlsArr(i).Text = ""
         End Select
    Next i[/COLOR]


    End With
    
    ActiveWorkbook.Save
    Application.ScreenUpdating = True
    Sheets("INCOME(1)").Range("A4").Select
    MsgBox "Month & Year Have Been Updated", vbInformation, "SUCCESSFUL MESSAGE"
    Unload MonthYearForm
End Sub
 

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
2,823
Anybody free to advise the correct code in the red part supplied above so the month and year values are entered into the correct cells please.
 

Forum statistics

Threads
1,081,860
Messages
5,361,737
Members
400,653
Latest member
ProParadox

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top