Please Check my VBA code

Meko1

New Member
Joined
Oct 20, 2020
Messages
44
Office Version
  1. 2016
Platform
  1. Windows
Hello
I would like a advanced VBA user to see my code pls.

I am just making simple if functions in VBA, but since I am new it is not that easy to me.

So the code is following:


If Sheet10.Range("N2").Value > 0 Then ActiveSheet.Range("B22").Value = 0.5
Else: Range("B22").Value = 0

If Sheet10.Range("M2").Value > 0 Then ActiveSheet.Range("B23").Value = 0.1
Else: Range("B23").Value = 0

If Sheet10.Range("L2").Value > 0 Then ActiveSheet.Range("B25").Value = 0.1
Else: Range("B25").Value = 0

If Sheet10.Range("J2").Value > 0 Then ActiveSheet.Range("B24").Value = 0.1
Else: Range("B24").Value = 0

If Sheet10.Range("K2").Value > 0 Then ActiveSheet.Range("B24").Value = 0.1
Else: Range("B24").Value = 0


So, am I correct, and while using else I want it to leave that cell with value 0.

And I have another issue, in other problem, while moving data from one sheet cells to another sheet cells, and those cells already have data inside, how to ask VBA if there is data go 1cell down and fill from there.

Tanks in advance.
Hope for your quick response.
 
I'm not sure what marked as solution means.
Does the script I provided work?
Most users here will make a written comment if the script worked.
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hey,
First thank you both I am trying to figure out the code, a bit difficult, something is going wrong.

It is 1st sheet but it was giving me an error now. After I removed the master name and replaced it with just Sheet1, its working but placing random numbers. I mean it starts count not from my active sheet but 2 sheets before.

Regarding your offer @MY Answer Is This, I will pass on it atm, since I am a student as well and time is quite limited for me.
 
Upvote 0
I am trying to figure out how it works, but I am not very familiar with the most of it so let me try if I can improve it anyhow
 
Upvote 0
Hey,
First thank you both I am trying to figure out the code, a bit difficult, something is going wrong.

It is 1st sheet but it was giving me an error now. After I removed the master name and replaced it with just Sheet1, its working but placing random numbers. I mean it starts count not from my active sheet but 2 sheets before.

Regarding your offer @MY Answer Is This, I will pass on it atm, since I am a student as well and time is quite limited for me.
Ok Just trying to help. I assume you mean you do not want my suggestion.
 
Upvote 0
My script wants you to have a sheet named "Master" which should be the first sheet in your workbook
Put your button with the script on the sheet named Master and all results will be shown in sheet named Master.
It's always best to use names when referring to the master sheet.
All the other sheets do not need to have a special name the script just looks at the sheet no matter the name.
 
Upvote 0
Yes, I understand your suggestion, it looks very tempting, but since the method, they are using at this moment is not fully functional, and writing one whole script, even though it will make the job even either, I think the little mistakes can just cause the loos in all the hard work if we did it. So even in my script/code as I like to call it, I have them all divided into segments since, if school decides to add or delete anything new it will be easier to cerrect
 
Upvote 0
Yes, I understand your suggestion, it looks very tempting, but since the method, they are using at this moment is not fully functional, and writing one whole script, even though it will make the job even either, I think the little mistakes can just cause the loos in all the hard work if we did it. So even in my script/code as I like to call it, I have them all divided into segments since, if school decides to add or delete anything new it will be easier to cerrect
OK.
Do not understand:
and writing one whole script?
I just wrote you the script.
You should not need any other scripts
 
Upvote 0
Yes I understand how the Sheet name works, problem is, the file is not only master sheet and students sheets, it like this: Master sheet, Bank statement sheet, Contract, blank sheet... and afterwards student sheets start, since I am using my ActiveSheet command for several macros I want to stand on ActiveSheet and to transfer the data into Master/ Sheet1.
 
Upvote 0
At the same time sheet4,7 and 8 does not even exist since I had them deleted
 
Upvote 0
At the same time sheet4,7 and 8 does not even exist since I had them deleted
The script looks at all the sheets in your workbook at the time the script is run.
It's appears as if you never tried the script. But if your happy with the way your doing it that's great. I'm not sure what I can do to help you
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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