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.
 
In my script you should see:
For i = 2 To Sheets.Count

This means it looks in all sheets except for sheet1 which should be named "Master"
The script does not care about sheet names
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Can you explain to me what i stands for in the script I do not understand it, and so if it is looking for all the sheets in the workbook can we ask it to start looking from Sheet10.
Thanks, I know I am asking a lot, and if I maid you uncomfortable and bored I am sorry for that
 
Upvote 0
funny you answered before I could even ask question :)
 
Upvote 0
and is there a way to change the sheet order, for example can I somehow modify for Sheet10 to be Sheet3 for example...
 
Upvote 0
Can you explain to me what i stands for in the script I do not understand it, and so if it is looking for all the sheets in the workbook can we ask it to start looking from Sheet10.
Thanks, I know I am asking a lot, and if I maid you uncomfortable and bored I am sorry for that
Yes we can start looking in sheet 10
change
For i = 2 To Sheets.Count
To:
For i = 10 To Sheets.Count
 
Upvote 0
I believe you still keep thinking I'm looking at sheet names.
The script is not looking at sheet names Like Sheet3

The only name it cares about is the sheet named "Master"
 
Upvote 0
Yes I understand, since I had not master I deleted ward master from the code and just typed Sheet1. and I did it on all the lines, never even thought just to change the name, give me few moments, I think I am close to it
 
Upvote 0
and when I type Sheet3 or Sheet1, I am referring to the sheets they have count in the VBA on the left side, names are in parenthesis
 
Upvote 0
Ok now weird thing is happening, macro is running but it does not transfer any data to Master sheet
 
Upvote 0
I'm not sure what your question is:
Your modifying the script and then saying it does not work.
Is there a problem with naming the first sheet in your workbook to Master

Why not try it and if it works and you just don't like the name Master Modify the script later.
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,384
Members
448,956
Latest member
JPav

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