VBA user input and adapt rows (in 2 sheets)

Jeofbist3

New Member
Joined
Jun 13, 2017
Messages
16
Hello everyone! I'm back on the forum since I need to dig into some VBA code (or not) that could help me on the following issue:

I want to create a textbox message where the user needs to give an input (= number of different products or services), then, macro will create/remove rows according this input on sheet1 and sheet2, for 3 different sections (volumes, unit prices & turnover).

Note that in sheet 1: column O is a formula, last year goes to 2025 (column BO). While sheet2: is refering directly to sheet1 (simply = the cell), same structure

The idea is then to avoid to complete manually the information when adding or removing products / service lines.

I hope it's clear, but don't hesitate to ask me for more info..

How can I start with the code?
Thanks a lot!
 

Attachments

  • VBA-sheet1.PNG
    VBA-sheet1.PNG
    47.3 KB · Views: 8
  • VBA-sheet2.PNG
    VBA-sheet2.PNG
    55.1 KB · Views: 8

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
I read your question and was stumped at this:
You said: I want to create a textbox message
What is textbox message.

Or do you mean a Input Box where you ask a question
 
Upvote 0
Hi, thanks for your reply. Yes, the input box could say: "How many products/services do you have?" Then the macro will create / adapt the number of rows equivalent to the answer.

Hope this is clearer!
 
Upvote 0
OK so a Inputbox pops up and says How many products and the user enters 14. So now what happens?
I do not understand what exactly now is suppose to happen with specific details.
 
Upvote 0
Hi! Sorry for the late reply.. So the situation is: if user enters 14, then it will create 14 extra rows in the file for each section (as from row #24, #28, #32, #42 and #46). I have then 15 products in total. Here is the code:

VBA Code:
Sub NewPoS()

Application.ScreenUpdating = False
Dim MyN As String
Dim i As Long, MyMarker As Long, MyM As Long, LstRW As Long
Dim ws As Worksheet: Set ws = Feuil1

MyN = InputBox("Give me a number", "My Input Box")
If Not IsNumeric(MyN) Then Exit Sub
MyN = CInt(MyN)
For MyMarker = 1 To 5
LstRW = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
MyM = Application.Match("Marker" & MyMarker, ws.Range(ws.Cells(1, 1), ws.Cells(LstRW, 1)), 0)
    For i = 1 To MyN
        ws.Rows(MyM + 2).EntireRow.Insert shift:=xlUp
    Next i
Next MyMarker

End Sub


My question: how can I adapt the code to keep the fomulas in columns O, AB, AO, etc.. (autofill function I guess?) Thanks a lot
 

Attachments

  • After macro (5 extra products).PNG
    After macro (5 extra products).PNG
    41.1 KB · Views: 3
  • Before macro.PNG
    Before macro.PNG
    45.4 KB · Views: 3
Upvote 0
Cross posted VBA - Applying Autofill with inserted rows (based on input box) and apply it to other sheet - OzGrid Free Excel/VBA Help Forum

While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,213,487
Messages
6,113,937
Members
448,534
Latest member
benefuexx

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