VBA Macro in button click error

jawaharprm

New Member
Joined
Dec 3, 2016
Messages
4
Hi iam Jawahar,
Assigined button in sheet 1 and code to process in sheet2 but macro is not running please help.

Sub Button2_Click()
Dim i As Integer
i = 2
Do While Sheet2.Cells(i, 2) <> ""
Cells(i, 38) = Cells(i, 36) - Cells(i, 37)
i = i + 1
Loop
For i = 1 To 10000
If (Cells(i, 39) = "") Then
Exit For
Else
If ((Cells(i, 39) = "706")) Then Cells(i, 39) = "6"
If ((Cells(i, 39) = "703")) Then Cells(i, 39) = "3"
If ((Cells(i, 39) = "702")) Then Cells(i, 39) = "2"
If ((Cells(i, 39) = "704")) Then Cells(i, 39) = "4"
If ((Cells(i, 39) = "713")) Then Cells(i, 39) = "13"
If ((Cells(i, 40) = "")) Then Cells(i, 40) = 0
End If
Next i
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
18,714
Office Version
  1. 2013
Platform
  1. Windows
Please tell us what your wanting to do instead of thinking we should understand your script which is not doing what you want.

Here is my script which is not working please help me with no explanation is not much help.
 

jawaharprm

New Member
Joined
Dec 3, 2016
Messages
4
Please tell us what your wanting to do instead of thinking we should understand your script which is not doing what you want.

Here is my script which is not working please help me with no explanation is not much help.


Hi,

wrote a script updatiing some cloums as given in script, i like to tag the script under button_clidk but the script is not running, Please help.
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
18,714
Office Version
  1. 2013
Platform
  1. Windows
If statements should be written like this:

If Cells(i, 39).value = "706" Then Cells(i, 39) = "6"
Not like this:

If ((Cells(i, 39) = "706")) Then Cells(i, 39) = "6"
 

jawaharprm

New Member
Joined
Dec 3, 2016
Messages
4
If statements should be written like this:

If Cells(i, 39).value = "706" Then Cells(i, 39) = "6"
Not like this:

If ((Cells(i, 39) = "706")) Then Cells(i, 39) = "6"


Hi thanks,

If ((Cells(i, 39) = "706")) Then Cells(i, 39) = "6" this if statment is working fine but my query is the entire code is not working under button click there is any code to add to run the code in button_click.
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,470
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
What happens if you put Sheet2. in front of everywhere it says Cells.
As M.A.I.T. has stated you don't need the extra brackets and you also don't need the quotes around the numbers if they are actual numbers and not text.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,528
Messages
5,837,884
Members
430,520
Latest member
VenkateshRajaganesan

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