I need help with a coding problem in VBA (Excel). Basically the place where I work has left me with the code in pic related (made by a previous employee) and has asked me to modify it.
What it does is when someone clicks the button it takes the text from the cells C2:D2 and puts it in the cells C12:D12. What I need it to do is to put the text from C2:D2 one cell down each time, so that the first time it's put in C12:D12, the second time in C13:D13, the third time in C14:D14 and so on and so forth.
The problem is, I have never coded in Visual Basic and don't have enough time to teach myself. Can anyone help me?
Declare a global integer and a global string. Assign the Value 12 to it, when the worksheet is opened. When the button is clicked, assign the string something like : "C"+ int + ":" + "D" + int. Then increment the int by 1. That's what I'd do.
Isaac Morris
Here You go, faggot. If you aren't totally useless, you'll figure out the rest for yourself. Code is tested and should work, if you replace Tabelle1 with Foglio1 and Schaltfläche1_Klicken() with CommandButton1_Click . You now just need to research how you set the value of x to 12 as a Starting point
Much obliged, will try. Appreciaed, but i am totally useless
Brody Ortiz
I just tried it, it gives me back a runtime error 1004. Wtf do I do now?
James Watson
Because I'm a nice guy Normally, this board isn't for spoonfeeding, but VBA for excel isn't easy to learn, and I guess this is a one time thing. There are plenty of youtube tutorials, however. If you wan't to learn something useful, consider doing it.
Post the code, so that I can help you. I'm no oracle, you know
Dylan Cox
Thanks for being a nice guy, Mr scary german guy. Fixed the runtime error but it doesn't work, will try again with your method
Camden Moore
Schaltfläche_Klicken()
why is this allowed
Nicholas Ortiz
Now it runs with no error, but it runs ass-backwards and starts from 55 instead of 12
Hudson Lewis
There's a reason nobody wants to learn VBA. And yet here I am, having to work with it regularly. Send Help. I advise everyone to avoid anything with "Visual Basic" in its name.
Elijah Martinez
I already said. Post the f'ing code or deal with it on your own.
Andrew Martinez
It's literally the same one you posted, but alright.
Dim x As Integer
Dim tmp As String
Sub CommandButton1_Click()
tmp = "C" + CStr(12 + x) + ":" + "D" + CStr(12 + x) Worksheets("Foglio2").range(tmp).Value2 = Worksheets("Foglio2").range("C2:D2").Value2 x = x + 1 End Sub
Brandon Hill
Idk if vba auto initializes shit, but could it be be because you didn't initialize those variables. Also why does vba calls it dim instead of a sane name like var
Sebastian Wood
I can't initialize it outside of a routine and if i initialize it inside i'm back at square one.
Nathan Stewart
Interesting. First of all, I'd advise you to reset the Code. You do this by clicking the stop-symbol in the vba-editor. Then try again to click the button. There is literally no reason for the macro to start at row 55. You don't "initialize" variables in VBA. It's just something you can't do globally. integers are automatically initialized with 0, and Strings with "" If he'd assign x a value in the Sub, it would just reset every time and he wouldn't go anywhere
Ryan Ramirez
Okay, code reset. What now?
Parker Green
How are you unable to figure this out?
Logan Torres
Write a new Value into C2:D2 for comparison, and click the button again. The code I wrote works for me. I wouldn't give you something i haven't tested myself.
Aaron Lee
It works now, thanks for being nice enough to save me from the weight of my own crushing incompetence
Evan Wright
i have literally never ever used visual basic, much less visual basic application, so you do the math
Owen Lopez
Ritardato. Come cazzo hanno fatto ad assumerti mi chiedo...
Connor Reyes
non siamo per nulla salati e/o infantili vedo
Cameron Collins
There's literally nothing wrong with using VB
Owen Lee
But I want to be an elitist dickhead.
I come from a Java background and have to use VBA now. Everything is just so unintuitive for me. But I'm willing to learn and share what I've learned with others. Still, It's fun to shit on VB and it's derivatives. If you're proficient in VBA it's a major selling point for big, traditional corporations and a good paycheck. At least here in Germany. I think there will be work for VBA-Developers the next 10 years still. It's use case is tailored solutions for a specific kind of company. Average Pajeets can't use it, scriptkiddies can't use it, and Jow Forumsentlemen as well as nu-males don't want to learn it.
Mason Adams
You need to use UsedRange. I forget the syntax but it would basically be UsedRange Rows + 1 to keep incrementing dynamically.