Userform to worksheet code advice

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,199
Office Version
  1. 2007
Platform
  1. Windows
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.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,213,535
Messages
6,114,192
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top