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.
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,563
Office Version
  1. 2013
Platform
  1. Windows
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
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Meko1

New Member
Joined
Oct 20, 2020
Messages
44
Office Version
  1. 2016
Platform
  1. Windows
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
 

Meko1

New Member
Joined
Oct 20, 2020
Messages
44
Office Version
  1. 2016
Platform
  1. Windows
funny you answered before I could even ask question :)
 

Meko1

New Member
Joined
Oct 20, 2020
Messages
44
Office Version
  1. 2016
Platform
  1. Windows
and is there a way to change the sheet order, for example can I somehow modify for Sheet10 to be Sheet3 for example...
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,563
Office Version
  1. 2013
Platform
  1. Windows

ADVERTISEMENT

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
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,563
Office Version
  1. 2013
Platform
  1. Windows
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"
 

Meko1

New Member
Joined
Oct 20, 2020
Messages
44
Office Version
  1. 2016
Platform
  1. Windows

ADVERTISEMENT

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
 

Meko1

New Member
Joined
Oct 20, 2020
Messages
44
Office Version
  1. 2016
Platform
  1. Windows
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
 

Meko1

New Member
Joined
Oct 20, 2020
Messages
44
Office Version
  1. 2016
Platform
  1. Windows
Ok now weird thing is happening, macro is running but it does not transfer any data to Master sheet
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,563
Office Version
  1. 2013
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,566
Messages
5,637,084
Members
416,956
Latest member
mitzhaki

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
Top