Function for making Excel Sheet

Gowodka

New Member
Joined
Aug 24, 2011
Messages
20
Hi All,

I'm new to the Visual Basic in Excel.
I'm trying to do the next thing, I have a lot of textboxes and comboboxes,
Now i need the data from them or i add the data of them to strings.

I Have different pages and on every page you got some boxes.

This is what i want to do

Code:
Gegevens = txtAbcZZZ  "," txtCbaZZZ
Workbooks.Open ("R:\08 Pack\Student\Automatisatie\Compleetfinito.xlsm")
RowCount = Workbooks("Compleetfinito.xlsm").Sheets("Incidenten").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Incidenten").Range("A1")
    .Offset(RowCount, 0) = Datum
    .Offset(RowCount, 1) = DatumMaand
    .Offset(RowCount, 2) = DatumWeek
    .Offset(RowCount, 3) = txtIncZZZ.Value
    .Offset(RowCount, 4) = cboAuteurZZZ.Value
    .Offset(RowCount, 5) = "Pu"
    .Offset(RowCount, 6) = "ZZZ"
    .Offset(RowCount, 8) = cboProbleemZZZ.Value
    .Offset(RowCount, 7) = txtMateriaalNummerZZZ.Value
    .Offset(RowCount, 9) = txtHoeveelheidZZZ.Value
    .Offset(RowCount, 10) = "stuks"
    .Offset(RowCount, 11) = txtOpmerkingenZZZ.Value
    .Offset(RowCount, 12) = Gegevens
End With
ActiveWorkbook.Save
ActiveWorkbook.Close

But i also need to do the next for another page

Code:
Gegevens = txtAbcXXX "," txtCbaXXX
Workbooks.Open ("R:\08 Pack\Student\Automatisatie\Compleetfinito.xlsm")
RowCount = Workbooks("Compleetfinito.xlsm").Sheets("Incidenten").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Incidenten").Range("A1")
    .Offset(RowCount, 0) = Datum
    .Offset(RowCount, 1) = DatumMaand
    .Offset(RowCount, 2) = DatumWeek
    .Offset(RowCount, 3) = txtIncXXX.Value
    .Offset(RowCount, 4) = cboAuteurXXX.Value
    .Offset(RowCount, 5) = "Pu"
    .Offset(RowCount, 6) = "XXX"
    .Offset(RowCount, 8) = cboProbleemXXX.Value
    .Offset(RowCount, 7) = txtMateriaalNummerXXX.Value
    .Offset(RowCount, 9) = txtHoeveelheidXXX.Value
    .Offset(RowCount, 10) = "stuks"
    .Offset(RowCount, 11) = txtOpmerkingenXXX.Value
    .Offset(RowCount, 12) = Gegevens
End With
ActiveWorkbook.Save
ActiveWorkbook.Close


So only the XXX and ZZZ differ i'm looking for a function or a code that i don't have to copy paste everything and make my code more cleaner.

Thanks in advance
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
After 2 days of looking up and looking up I found the answer

Put into module the next code

Code:
'---------------------
'Update de Algemene Excel Sheet
'---------------------

Public Sub MakeExcelMain(Incident, Uur, Ploeg, Auteur, OperatorInc, OperatorVast, MateriaalNummer, _
    Product, Leverancier, Minizone, Lijn, Probleem, Oorzaak, Acties)
    
Worksheets("sheet1").Activate
RowCount = Workbooks("Back UP 4.xlsm").Sheets("sheet1").Range("A1").CurrentRegion.Rows.Count
With Worksheets("sheet1").Range("A1")
    .Offset(RowCount, 6) = Incident
    .Offset(RowCount, 7) = DatumJaar
    .Offset(RowCount, 8) = DatumMaand
    .Offset(RowCount, 9) = DatumWeek
    .Offset(RowCount, 10) = Datum
    .Offset(RowCount, 11) = Uur
    .Offset(RowCount, 12) = Ploeg
    .Offset(RowCount, 13) = Auteur
    .Offset(RowCount, 14) = OperatorInc
    .Offset(RowCount, 15) = OperatorVast
    .Offset(RowCount, 17) = MateriaalNummer
    .Offset(RowCount, 18) = Product
    .Offset(RowCount, 19) = Leverancier
    .Offset(RowCount, 23) = Minizone
    .Offset(RowCount, 24) = Lijn
    .Offset(RowCount, 25) = "Packaging error"
    .Offset(RowCount, 27) = Probleem
    .Offset(RowCount, 28) = Gegevens
    .Offset(RowCount, 29) = Oorzaak
    .Offset(RowCount, 30) = Acties
ActiveWorkbook.Save
End With
End Sub

then put in userform ( for example under a commandbutton)

Code:
MakeExcelMain txtIncAenR, txtStartUur, txtStartPloeg, cboAuteurAenR.Value, txtStartOperatorInc, txtStartOperatorVast, _
    txtMateriaalNummerAenR, txtStartProduct, Leverancier, txtStartMinizone, txtStartLijn, cboProbleemAenR.Value, _
    txtStartOorzaak, txtStartActies

The thing i struggled with the most are NOT to use parenthesses
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,504
Members
452,917
Latest member
MrsMSalt

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