userform VB problem

Mattlake

Board Regular
Joined
Apr 9, 2020
Messages
87
Office Version
  1. 2021
Platform
  1. Windows
Hi

I am so sorry to ask this.

I have created (with a lot of help from this forum) a spreadsheet with a userform. I have come across an issue that I have a formula in column I (date column) that is down to line 400.

when i fill the form in it goes to line 401.

I am assuming that I would need to put in a VB command to say when i press add it pastes the fields and then paste the formula in after. is this possible? if it is any ideas on what this can be?

the below is the script that i seem to get working

VBA Code:
Private Sub cmdAdd_Click()

Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("2023")

iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

With ws
.Cells(iRow, 1).Value = Me.ComboBox2.Value
.Cells(iRow, 2).Value = Me.ComboBox1.Value
.Cells(iRow, 3).Value = Me.TextBox1.Value
.Cells(iRow, 4).Value = Me.ComboBox3.Value
.Cells(iRow, 5).Value = Me.TextBox2.Value
.Cells(iRow, 6).Value = Me.ComboBox4.Value
.Cells(iRow, 7).Value = Me.ComboBox5.Value
.Cells(iRow, 8).Value = Me.ComboBox6.Value
.Cells(iRow, 10).Value = Me.ComboBox7.Value
.Cells(iRow, 11).Value = Me.ComboBox8.Value
.Cells(iRow, 12).Value = Me.TextBox3.Value
.Cells(iRow, 13).Value = Me.TextBox4.Value
.Cells(iRow, 14).Value = Me.TextBox5.Value
.Cells(iRow, 15).Value = Me.ComboBox9.Value
.Cells(iRow, 16).Value = Me.ComboBox11.Value
.Cells(iRow, 17).Value = Me.ComboBox12.Value
.Cells(iRow, 18).Value = Me.ComboBox10.Value
.Cells(iRow, 20).Value = Me.ComboBox13.Value
.Cells(iRow, 9).Value = concatenate(F2, " ", G2, " ", H2)
.Cells(iRow, 19).Value = concatenate(P2, " ", q2, " ", R2)



End With
Me.ComboBox1.Value = ""
Me.ComboBox2.Value = ""
Me.ComboBox3.Value = ""
Me.ComboBox4.Value = ""
Me.ComboBox5.Value = ""
Me.ComboBox6.Value = ""
Me.ComboBox7.Value = ""
Me.ComboBox8.Value = ""
Me.ComboBox9.Value = ""
Me.ComboBox10.Value = ""
Me.ComboBox11.Value = ""
Me.ComboBox12.Value = ""
Me.ComboBox13.Value = ""
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.TextBox5.Value = ""


End Sub

I think i have put the concatenate in wrong.

any help would be appreciated
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Try this:

VBA Code:
    .Cells(iRow, 9).Value = .Range("F2") & " " & .Range("G2") & " " & .Range("H2")
    .Cells(iRow, 19).Value = .Range("P2") & " " & .Range("Q2") & " " & .Range("R2")
 
Upvote 0
Entering the formula or entering the value

VBA Code:
.Cells(iRow, 9).Value = "=CONCATENATE(F2,"" "",G2,"" "",H2)"
.Cells(iRow, 9).Value= WorksheetFunction.TextJoin(" ", True, Range("F2:H2"))
 
Upvote 0
thank you i thought i was trying too hard.

this one seems to work
VBA Code:
    .Cells(iRow, 9).Value = [F2] & " " & [G2] & " " & [H2]
    .Cells(iRow, 19).Value = [P2] & " " & [Q2] & " " & [R2]

only question do i replace the F2 G2 etc with irow,6 and irow,7 etc? to get it to copy downwards?
 
Upvote 0
only question do i replace the F2 G2 etc with irow,6 and irow,7 etc? to get it to copy downwards?

In that case, if the result depends on the data in the row (iRow):
VBA Code:
    .Cells(iRow, 9).Value = .Range("F" & iRow) & " " & .Range("G" & iRow) & " " & .Range("H" & iRow)
    .Cells(iRow, 19).Value = .Range("P" & iRow) & " " & .Range("Q" & iRow) & " " & .Range("R" & iRow)
 
Upvote 0
Solution
it is always so simple when others show you the way :)

Thank you for your help with this
 
Upvote 0

Forum statistics

Threads
1,214,577
Messages
6,120,359
Members
448,956
Latest member
Adamsxl

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