Enter value in one Excel sheet and generate values in another worksheet. This video is based on a query by a website visitor:
First of all, thank you for all the interesting excel VBA tutorials you've made!
I'm a swedish student from Malmö, studying bachelor in civil engineering and is now writing my candidate paper. In my paper I thought to include an excelfile but I've got some problems with macros and VBA.
What I want to do:
The user gives a number (days) and excel (the macro) generates a list with the same amount of numbers as it is days (a list with 1,2,3...) in another sheet.
the user will also write a price per unit that is supposed to complete the list next to the numbers.
I don't know if my explanation above is any good, so I'll give you my code. I't doesn't work and I would be very glad if you could help me.
Private Sub cmd_addit_Click()
Dim number, x, x1, antaltimmar As Integer
x1 = 1 'row 1 (so excel knows) I've made a list starting in L1 with 1 L2 with 2 and so on.
x = 4 'row 4, this is the starting row, where I want excel to start paste info.
number = 1 'it is always at least 1 day.
Do Until number = antaldagar 'Amount of days should be the same as in the list.
Worksheets("Blad1").Select 'chose sheet1 to get info from
antaldagar = Range("C10") 'antaldagar value from C10.
Worksheets("blad1").Range(Cells(x1, 12)).Copy 'copy from cell Lx1
Worksheets("blad2").Select 'go to workbook Blad2 (sheet2)
Worksheets("blad2").Range("Cells(x, 3)").Paste 'paste from cell Lx1 to column C (3) row x.
x = x + 1 'next row
x1 = x1 + 1 'next row
number = number + 1 'add 1 number until it's equal to number of days
Thanks in advance!
Amanda W '
We use a 'for loop' and selection of different worksheets at appropriate steps to solve the problem.
Feel free to subscribe to my channel!
For more knowledge read the book Excel 2016 Power Programming with VBA: http://amzn.to/2kDP35V
If you are from India you can get this book here: http://amzn.to/2jzJGqU
Tags: Enter value in one Excel sheet and generate values in another worksheet, command button, for loop, excel vba